Good morning all,
I'm battling with some code that takes a report and sends it out to a client, with a filename built from the [Customer ID] and [QuoteRef] fields.
This is my current code:
When I preview the report, the report has the correct name at the top, but for some unknown reason when I use the "email" button, which runs the above code, no matter which record I am on the attached pdf is AALWAYS named FUR001-13545.
When I open the file, the file is correct.
For example if i raise a quote for client SPE001 with reference 16097, the attachment is called FUR001-13545 but the reference and internals of the file match those of SPE001-16097
Any ideas where this is going wrong?
I'm battling with some code that takes a report and sends it out to a client, with a filename built from the [Customer ID] and [QuoteRef] fields.
This is my current code:
Code:
Private Sub Command22_Click()
On Error Resume Next ' Suppress error messages temporarily
' Open the report in preview mode with a filter based on [QuoteRef]
DoCmd.OpenReport "rptQuote", acViewPreview, , "[QuoteRef] = '" & Me.[QuoteRef] & "'", acWindowNormal
' Check if the report is open before attempting to send the email
If CurrentData.AllReports("rptQuote").IsLoaded Then
' Extract the first word from the field Rep_ID to use as the recipient's first name
Dim recipientFirstName As String
recipientFirstName = StrConv(Split(Me.[Rep_ID], " ")(0), vbProperCase) ' Convert to proper case
' Construct a more personalized email body
Dim emailBody As String
emailBody = "Dear " & recipientFirstName & "," & vbCrLf & vbCrLf & _
"I trust this email finds you well. Attached, please find the quotation against your reference No: " & Me.[CustomerRef] & "." & vbCrLf & vbCrLf & _
"Please review the attached document, and do not hesitate to contact us if you have any questions or require further clarification." & vbCrLf & vbCrLf & _
"For any orders that may arise from this quotation, kindly send them to orders@clarityndt.co.uk." & vbCrLf & vbCrLf & _
"Thank you for considering Clarity NDT for your requirements." & vbCrLf & vbCrLf & _
"Best regards," & vbCrLf & _
"Clarity NDT Limited"
' Send email with the report attached as a PDF and the personalized email body
DoCmd.SendObject acSendReport, "rptQuote", acFormatPDF, , "", "", _
"Quotation against your reference No: " & Me.[CustomerRef], emailBody, True
' Close the report after sending the email
DoCmd.Close acReport, "rptQuote"
Else
MsgBox "The report 'rptQuote' is not open.", vbExclamation
End If
On Error GoTo 0 ' Reset error handling to default behavior
End Sub
When I preview the report, the report has the correct name at the top, but for some unknown reason when I use the "email" button, which runs the above code, no matter which record I am on the attached pdf is AALWAYS named FUR001-13545.
When I open the file, the file is correct.
For example if i raise a quote for client SPE001 with reference 16097, the attachment is called FUR001-13545 but the reference and internals of the file match those of SPE001-16097
Any ideas where this is going wrong?