E m a i l Invoice from Customer Order Form with Command button

roh710

New member
Local time
Today, 08:09
Joined
Feb 1, 2013
Messages
5
I am trying to send invoices via e m a i l.

I have an invoice form and once the form is filled in, I can create invoice with click of command button.

What I want to do from this point is to create another command button for emailing the Invoice (Report) as an attachment (PDF) to the customer's email address already in the form, in the following format:

Dear [Customer's name]:

[e m a i l body]

ABC Co
123 main st
anytown, USA

Can anyone help to achieve this task?

Thank you in advance!

Keith-R
 
Last edited:
Try this out.

Code:
[SIZE=3][FONT=Arial]Private Sub Command1_Click()[/FONT][/SIZE]
[SIZE=3][FONT=Arial]On Error GoTo Err_Command1_Click[/FONT][/SIZE]
[SIZE=3][FONT=Arial]  Dim stReportPathName As String[/FONT][/SIZE]
[SIZE=3][FONT=Arial]  Dim stDocName As String[/FONT][/SIZE]
[SIZE=3][FONT=Arial]  Dim stLinkCriteria As String    [/FONT][/SIZE]
[SIZE=3][FONT=Arial]    stReportPathName = "C:\Users\" & Environ("UserName") & "\Desktop\Name you want the file to be-" & Me!ThePrimaryID & Format(Date, "-MMDDYYYY") & ".pdf"[/FONT][/SIZE]
[SIZE=3][FONT=Arial]  stDocName = "Your Report Name Here"[/FONT][/SIZE]
[SIZE=3][FONT=Arial]  stLinkCriteria = "[ThePrimaryID]=" & Me![ThePrimaryID]    [/FONT][/SIZE]
[SIZE=3][FONT=Arial]  DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria, acHidden[/FONT][/SIZE]
[SIZE=3][FONT=Arial]  DoCmd.SendObject acSendReport, "Your Report Name Here", acFormatPDF, , , , , , "Body of Email", True    [/FONT][/SIZE]
[SIZE=3][FONT=Arial]Exit_Command1_Click:[/FONT][/SIZE]
[SIZE=3][FONT=Arial]  Exit Sub[/FONT][/SIZE]
[SIZE=3][FONT=Arial]Err_Command1_Click:[/FONT][/SIZE]
[SIZE=3][FONT=Arial]  MsgBox "Your email was not sent, please close and try again"[/FONT][/SIZE]
[SIZE=3][FONT=Arial]  Me.Requery    [/FONT][/SIZE]
[SIZE=3][FONT=Arial]  Resume Exit_Command1_Click    [/FONT][/SIZE]
[SIZE=3][FONT=Arial]End Sub[/FONT][/SIZE]
 
I was able to get the code below to work over the weekend at home. However, when I came to my office this morning and tried to run the code, it' gave me following error message:

Run-time error '2282':
The formats in which you are attempting to output the current object is not available.

It looks like the report "OrderAcknowledgement" is not being converted to PDF file.

Can anyone see anything wrong with the code below?
The code halts at the highlighed nin blue area

Private Sub cmdEmail_Click()
' On Error GoTo Err_cmdEmail_Click
Dim stReportPathName As String
Dim stDocName As String
Dim stLinkCriteria As String
Dim stConfEmail As String
Dim stSubject As String
Dim stMessageText As String
stConfEmail = [ConfEmail]
stLinkCriteria = "[Order_ID]=" & Me![Order_ID]
stReportPathName = "C:\Documents and Settings\User\Desktop\[--------]\SO\OrderAcknowledgement-" & Me!Order_ID & Format(Date, "-MMDDYYYY") & ".pdf"
stDocName = "OrderAcknowledgement"
stSubject = "Order Acknowledgement - Your PO# " & [PO_No]
stMessageText = "Dear Customer -" & vbCrLf & vbCrLf & _
"Thank you for your recent order placed with our company. We are doing everything we are able to ship out your order on the same day." & vbCrLf & vbCrLf & _
"The Order Acknowledgement for your purchase order number " & [PO_No] & ", is attached for your record." & vbCrLf & vbCrLf & _
"If you have any questions and/or concerns regarding your order, please contact our Customer Service Department through below contact information." & vbCrLf & vbCrLf & _
" ● Telephone: (000) 000-0000" & vbCrLf & _
" ● Email: [E m a i l Address]" & vbCrLf & vbCrLf & _
"Yours Truly," & vbCrLf & vbCrLf & "Customer Service"
DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria, acHidden
DoCmd.SendObject acSendReport, "OrderAcknowledgement", acFormatPDF, stConfEmail, , , stSubject, stMessageText, True
Exit_cmdEmail_Click:
Exit Sub
Err_cmdEmail_Click:
MsgBox "The Order Acknowledgement was not sent." & vbCrLf & vbCrLf & "Please close and try again!"
Me.Requery
Resume Exit_cmdEmail_Click
End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom