Hi all,
As you probably can see I'm new to this forum. My apologies if my English has some (major) flaws.
I have been working on an Access database, more or less based on an existing one, but in a different way.
Everything is running very well, but I noticed one problem that causes us to send a specific supplier of us a wrong quality analysis report.
I will try to give a short version of what happens and when it happens:
* We enter some values in a form, which are obviously stored in a table;
* When everything is entered, we click on a button to send an email with a quality analysis attached (as a PDF);
* Quality analysis is based on a specific record;
* When e-mail is generated with the attachment added we can send it without any problem;
Now the catch!
* When we cancel the e-mail, in the background the report is ofcourse generated and keeps excisting with specific record/data mentioned in this e-mail;
* When we go to another record and want to send the new quality analysis, the e-mail is generated with the old quality analysis attached.
What I want is the generated report to be cancelled when I cancel the e-mail. Now the report only looses the "filter" when the e-mail is sent.
Maybe this question has to be placed in the report section of this forum, but I keep thinking that this is caused by the VB for sending the email (see below).
Code:
Private Sub Knop239_Click()
On Error GoTo Err_Knop239_Click
Dim strReportName As String
Dim strCriteria As String
Dim strEmailto As String
Dim strMessageEmail As String
strReportName = "Quality Analysis"
strCriteria = "[CONTRACTNR]='" & Me!CONTRACTNR & "'"
strEmailto = Me.E_MAIL
strMessageEmail = "Dear Supplier," & _
vbNewLine & vbNewLine & _
"Enclosed you find our Quality Analysis of the last delivery." & _
vbNewLine & vbNewLine & _
"If we send an outturn sample to you because of some remarks, please reply within 5 working days after receiving the sample. We kindly ask you to e-mail your reply to XXX, XXX and XXX." & _
vbNewLine & vbNewLine & _
"With kind regards," & _
vbNewLine & vbNewLine & _
"XXX" & _
vbNewLine & _
"XXX" & _
vbNewLine & _
"XXX"
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria, acWindowNormal
DoCmd.SendObject acSendReport, strReportName, acFormatPDF, strEmailto, "XXX;XXX;XXX", , "Quality Analysis " & Me.CONTRACTNR & " " & Me.LEVERANC, strMessageEmail
DoCmd.Close acReport, strReportName, acSaveNo
Exit_Knop239_Click:
Exit Sub
Err_Knop239_Click:
Select Case Err 'specific Case statements for errors we can anticipate, the "Else" catches any others
Case 2501 'Action OpenReport was cancelled.
MsgBox "Klik op Afdrukvoorbeeld sluiten!"
DoCmd.Hourglass False
Resume Exit_Knop239_Click
Case Else
MsgBox Err.Description
DoCmd.Hourglass False
Resume Exit_Knop239_Click
End Select
End Sub
* Please note that I'm not at all a VBA and/or Access specialist. I know the basics, but not more than that.
Thank you all in advance for your help!
Kind regards,
Stefan