Access creating Emails from stored data.. (1 Viewer)

StuartG

Registered User.
Local time
Today, 14:07
Joined
Sep 12, 2018
Messages
125
Good luck!

Oh this was fun and been a head scratching thing, with still no results. I copied the code per your advisement and i still cannot get it open an outlook message window.
What have i done wrong?

Function SendEmail()

Dim strTo As String
Dim strSubject As String
Dim strBody As String
Dim bEdit As Boolean

'Send Email using late binding to avoid reference issues
Dim objOutlook As Object
Dim objOutlookMsg As Object
Dim objOutlookRecip As Object
Dim objOutlookAttach As Object
Dim i As Integer
Const olMailItem = 0

On Error GoTo ErrorMsgs

Set objOutlook = CreateObject("Outlook.Application")

Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add("stuart.ginns@thermofisher.com")
objOutlookRecip.Type = 1

If Not IsMissing(strBCC) Then
Set objOutlookRecip = .Recipients.Add
objOutlookRecip.Type = 3
End If

.Subject = strSubject
.Body = strBody
.Importance = 2 'Importance Level 0=Low,1=Normal,2=High

' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
If IsArray(AttachmentPath) Then
For i = LBound(AttachmentPath) To UBound(AttachmentPath) - 1
If AttachmentPath(i) <> "" And AttachmentPath(i) <> "False" Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath(i))
End If
Next i
Else
If AttachmentPath <> "" Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
End If
End If

For Each objOutlookRecip In .Recipients
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next

If bEdit Then 'Choose btw transparent/silent send and preview send
.Display
Else
.Send
End If
End With

Set objOutlookMsg = Nothing
Set objOutlook = Nothing
Set objOutlookRecip = Nothing
Set objOutlookAttach = Nothing

ErrorMsgs:
If Err.Number = "287" Then
MsgBox "You clicked No to the Outlook security warning. " & _
"Rerun the procedure and click Yes to access e-mail " & _
"addresses to send your message. For more information, " & _
"see the document at http://www.microsoft.com/office" & _
"/previous/outlook/downloads/security.asp."
Exit Function
ElseIf Err.Number <> 0 Then
MsgBox Err.Number & " - " & Err.Description
Exit Function
End If
End Function
 

isladogs

MVP / VIP
Local time
Today, 14:07
Joined
Jan 14, 2017
Messages
18,186
Another approach is to use Collaborative Data Objects (CDO).
This allows you to send emails either via Outlook or direct from Access.
You can send plain text or HTML emails, include both images and data and also include attachments.
In other words, almost everything you can do by sending an email from Outlook itself.
All you need to know are your email account settings.
If you are interested, try my CDO Email Tester
 

StuartG

Registered User.
Local time
Today, 14:07
Joined
Sep 12, 2018
Messages
125
Another approach is to use Collaborative Data Objects (CDO).
This allows you to send emails either via Outlook or direct from Access.
You can send plain text or HTML emails, include both images and data and also include attachments.
In other words, almost everything you can do by sending an email from Outlook itself.
All you need to know are your email account settings.
If you are interested, try my CDO Email Tester

Thank you for the tip, i will have a look at this also, is this just a simple export the items from this Database and then import to my current DB?

I am intrigued though on where all the message text goes or is it all derived from an attachment?

The code I had used previously creates a memo style email which the user can edit before sending, however I need to attach the same attachment after i open everything.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:07
Joined
Oct 29, 2018
Messages
21,357
Oh this was fun and been a head scratching thing, with still no results. I copied the code per your advisement and i still cannot get it open an outlook message window.
What have i done wrong?
Hi. It doesn't look like you copied the code correctly. You weren't supposed to make any changes to it. For example, you said you have the following at the top of your code:


Code:
 Function SendEmail()
Whereas, the one from the website looks like this:
Code:
[COLOR=#E56717][B]Function[/B][/COLOR] SendEmail(strTo [COLOR=#151B8D][B]As[/B][/COLOR] [COLOR=#F660AB][B]String[/B][/COLOR], strSubject [COLOR=#151B8D][B]As[/B][/COLOR] [COLOR=#F660AB][B]String[/B][/COLOR], strBody [COLOR=#151B8D][B]As[/B][/COLOR] [COLOR=#F660AB][B]String[/B][/COLOR], bEdit [COLOR=#151B8D][B]As[/B][/COLOR] [COLOR=#F660AB][B]Boolean[/B][/COLOR], _                    [COLOR=#151B8D][B]Optional[/B][/COLOR] strBCC [COLOR=#151B8D][B]As[/B][/COLOR] [COLOR=#F660AB][B]Variant[/B][/COLOR], [COLOR=#151B8D][B]Optional[/B][/COLOR] AttachmentPath [COLOR=#151B8D][B]As[/B][/COLOR] [COLOR=#F660AB][B]Variant[/B][/COLOR])

See all those missing stuff? If you still want to try Daniel's function, try the following steps:


1. Copy the code from his website
2. Go to the VBE window and create a new Standard Module
3. Paste the code in the VBE window
4. Save the module and call it something like modSendEmail
5. In the Immediate Window, try entering the following
Code:
SendEmail "testemail@somewhere.com","Subject","Message",True
Let us know what happens...
 

StuartG

Registered User.
Local time
Today, 14:07
Joined
Sep 12, 2018
Messages
125
Hi. It doesn't look like you copied the code correctly. You weren't supposed to make any changes to it. For example, you said you have the following at the top of your code:


Code:
 Function SendEmail()
Whereas, the one from the website looks like this:
Code:
[COLOR=#E56717][B]Function[/B][/COLOR] SendEmail(strTo [COLOR=#151B8D][B]As[/B][/COLOR] [COLOR=#F660AB][B]String[/B][/COLOR], strSubject [COLOR=#151B8D][B]As[/B][/COLOR] [COLOR=#F660AB][B]String[/B][/COLOR], strBody [COLOR=#151B8D][B]As[/B][/COLOR] [COLOR=#F660AB][B]String[/B][/COLOR], bEdit [COLOR=#151B8D][B]As[/B][/COLOR] [COLOR=#F660AB][B]Boolean[/B][/COLOR], _                    [COLOR=#151B8D][B]Optional[/B][/COLOR] strBCC [COLOR=#151B8D][B]As[/B][/COLOR] [COLOR=#F660AB][B]Variant[/B][/COLOR], [COLOR=#151B8D][B]Optional[/B][/COLOR] AttachmentPath [COLOR=#151B8D][B]As[/B][/COLOR] [COLOR=#F660AB][B]Variant[/B][/COLOR])

See all those missing stuff? If you still want to try Daniel's function, try the following steps:


1. Copy the code from his website
2. Go to the VBE window and create a new Standard Module
3. Paste the code in the VBE window
4. Save the module and call it something like modSendEmail
5. In the Immediate Window, try entering the following
Code:
SendEmail "testemail@somewhere.com","Subject","Message",True
Let us know what happens...

OK, so this is copied exactly from his website.
When i click the play button in the VBA to test code it asks me to save a macro? :confused::confused::confused:

Option Compare Database

---------------------------------------------------------------------------------------
' Procedure : SendEmail
' Author : CARDA Consultants Inc.
' Website : http://www.cardaconsultants.com
' Purpose : Automate Outlook to send emails with or without attachments
' Copyright : The following may be altered and reused as you wish so long as the
' copyright notice is left unchanged (including Author, Website and
' Copyright). It may not be sold/resold or reposted on other sites (links
' back to this site are allowed).
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' strTo To Recipient email address string (semi-colon separated list)
' strSubject Text string to be used as the email subject line
' strBody Text string to be used as the email body (actual message)
' bEdit True/False whether or not you wish to preview the email before sending
' strBCC BCC Recipient email address string (semi-colon separated list)
' AttachmentPath single value or array of attachment (complete file paths with
' filename and extensions)
'
' Revision History:
' Rev Date(yyyy/mm/dd) Description
' **************************************************************************************
' 1 2007-Nov-16 Initial Release
'---------------------------------------------------------------------------------------
Function SendEmail(strTo As String, strSubject As String, strBody As String, bEdit As Boolean, _
Optional strBCC As Variant, Optional AttachmentPath As Variant)
'Send Email using late binding to avoid reference issues
Dim objOutlook As Object
Dim objOutlookMsg As Object
Dim objOutlookRecip As Object
Dim objOutlookAttach As Object
Dim i As Integer
Const olMailItem = 0

On Error GoTo ErrorMsgs

Set objOutlook = CreateObject("Outlook.Application")

Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add(strTo)
objOutlookRecip.Type = 1

If Not IsMissing(strBCC) Then
Set objOutlookRecip = .Recipients.Add(strBCC)
objOutlookRecip.Type = 3
End If

.Subject = strSubject
.Body = strBody
.Importance = 2 'Importance Level 0=Low,1=Normal,2=High

' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
If IsArray(AttachmentPath) Then
For i = LBound(AttachmentPath) To UBound(AttachmentPath) - 1
If AttachmentPath(i) <> "" And AttachmentPath(i) <> "False" Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath(i))
End If
Next i
Else
If AttachmentPath <> "" Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
End If
End If

For Each objOutlookRecip In .Recipients
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next

If bEdit Then 'Choose btw transparent/silent send and preview send
.Display
Else
.Send
End If
End With

Set objOutlookMsg = Nothing
Set objOutlook = Nothing
Set objOutlookRecip = Nothing
Set objOutlookAttach = Nothing

ErrorMsgs:
If Err.Number = "287" Then
MsgBox "You clicked No to the Outlook security warning. " & _
"Rerun the procedure and click Yes to access e-mail " & _
"addresses to send your message. For more information, " & _
"see the document at http://www.microsoft.com/office" & _
"/previous/outlook/downloads/security.asp."
Exit Function
ElseIf Err.Number <> 0 Then
MsgBox Err.Number & " - " & Err.Description
Exit Function
End If
End Function
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:07
Joined
Oct 29, 2018
Messages
21,357
Hi. No, don't click on the play button. Instead, go to the Immediate Window (Ctrl+G) and type the code I posted earlier to test it.
 

StuartG

Registered User.
Local time
Today, 14:07
Joined
Sep 12, 2018
Messages
125
Hi. No, don't click on the play button. Instead, go to the Immediate Window (Ctrl+G) and type the code I posted earlier to test it.

got ya, ok, so that worked, it bought up the outlook new message window in the format you had specified in the code.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:07
Joined
Oct 29, 2018
Messages
21,357
Excellent! So now, in the code where you're trying to send an email, all you have to do is construct the pieces you need to pass as arguments. For example, you might have something like:


Code:
Dim ToAddress As String
Dim EmailSubj As String
Dim EmailMessage As String

ToAddress = "someone@somewhere.com"
EmailSubj = "Test Email"
EmailMessage = "This is the message body of the email."

SendEmail ToAddress, EmailSubj, EmailMessage, True
 

StuartG

Registered User.
Local time
Today, 14:07
Joined
Sep 12, 2018
Messages
125
Excellent! So now, in the code where you're trying to send an email, all you have to do is construct the pieces you need to pass as arguments. For example, you might have something like:


Code:
Dim ToAddress As String
Dim EmailSubj As String
Dim EmailMessage As String

ToAddress = "someone@somewhere.com"
EmailSubj = "Test Email"
EmailMessage = "This is the message body of the email."

SendEmail ToAddress, EmailSubj, EmailMessage, True

is this somewhere in the code that you recommended or do i add this at the bottom of existing code i pasted?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:07
Joined
Oct 29, 2018
Messages
21,357
Hi Stuart. We're done with the code from Daniel. You just save it and put it away. From this point on, we just use it wherever we need to send an email. So, how were you initiating an email message to begin with? If you were using a form, for example, then you'll need to place code behind that form to call the function to send an email. For instance, you could add a button to initiate the email message.
 

StuartG

Registered User.
Local time
Today, 14:07
Joined
Sep 12, 2018
Messages
125
Hi Stuart. We're done with the code from Daniel. You just save it and put it away. From this point on, we just use it wherever we need to send an email. So, how were you initiating an email message to begin with? If you were using a form, for example, then you'll need to place code behind that form to call the function to send an email. For instance, you could add a button to initiate the email message.

Oh Ok, i thought that was the code that was actually operating Outlook :banghead:

Well i know you mentioned previously a template would be better however after speaking with colleagues at work they would prefer it to be pre filled text (memo Style, or like blank new email)

I was dabbling in other codes at wrote this yesterday, though it was convoluted and cumbersome but gave me the output i wanted.

Code:
Public Function SendEmail2()

Dim varName As Variant
Dim varCC As Variant
Dim varSubject As Variant
Dim varBody1 As Variant
Dim varBody2 As Variant


varName = ""
varCC = ""
'separate each email by a ','

varSubject = "Acknowledgement Of Receipt"
'Email subject

varBody1 = "Dear" & Chr(10) & "" & Chr(10) & "Thank you for your purchase order." & Chr(10) & "" & Chr(10) & "Customer Purchase Order Reference:" & Chr(9) & ":-" & Chr(10) & "Product Line Ordered:" & Chr(9) & "" & Chr(9) & "" & Chr(9) & ":-" & Chr(10) & "Quote Reference:" & Chr(9) & "" & Chr(9) & "" & Chr(9) & ":-" & Chr(10) & "Total Order Value:" & Chr(9) & "" & Chr(9) & "" & Chr(9) & ":-" & Chr(10) & "" & Chr(10) & ""
varBody2 = "Please note that this is only an acknowledgement of your receipt of your order and your contract to purchase these items is not complete until we send you an order confirmation" & Chr(10) & "" & Chr(10) & "Attached is a copy of the Thermo Fisher Scientific General Terms and Conditions of Sale July 2010, which will apply to this order" & Chr(10) & "" & Chr(10) & "Please be aware that deliveries will be arranged to a ground floor warehouse/goods in, unless previously discussed and agreed with Thermo Fisher Scientific Area Account manager who coordinated this instrument purchase" & Chr(10) & "" & Chr(10) & "If a non-standard delivery is required (e.g. to a 1st floor laboratory) and is not included in the shipping of this instrument, please contact us and we can arrange a quotation from a specialist courier for you" & Chr(10) & "" & Chr(10) & "If you have any questions in the meantime please do not hesitate to contact us." & Chr(10) & "" & Chr(10) & "Kind Regards"




'Body of the email
DoCmd.SendObject , , , varName, varCC, , varSubject, varBody1 + varBody2, True, False
'Send email command. The True after "varBody" allows user to edit email before sending.
'The False at the end will not send it as a Template File

End Function 

i attach a picture of the end result, this is how my colleaues would prefer the output, however when they click that at the window opens it needs to include an attachment.

Hope i haven't confused things?
 

Attachments

  • Code output.jpg
    Code output.jpg
    96.1 KB · Views: 83

theDBguy

I’m here to help
Staff member
Local time
Today, 07:07
Joined
Oct 29, 2018
Messages
21,357
Oh Ok, i thought that was the code that was actually operating Outlook :banghead:
Yes, it was the one "automating" Outlook. All we need to do is pass the things it needs/requests to in-turn pass to Outlook to generate the email message.


I was dabbling in other codes at wrote this yesterday, though it was convoluted and cumbersome but gave me the output i wanted.
This is good. We just need to modify it to use the new function now. For example, you could try:


Code:
Public Function SendEmail2()

Dim varName As Variant
Dim varCC As Variant
Dim varSubject As Variant
Dim varBody1 As Variant
Dim varBody2 As Variant


varName = ""
varCC = ""
'separate each email by a ','

varSubject = "Acknowledgement Of Receipt"
'Email subject

varBody1 = "Dear" & Chr(10) & "" & Chr(10) & "Thank you for your purchase order." & Chr(10) & "" & Chr(10) & "Customer Purchase Order Reference:" & Chr(9) & ":-" & Chr(10) & "Product Line Ordered:" & Chr(9) & "" & Chr(9) & "" & Chr(9) & ":-" & Chr(10) & "Quote Reference:" & Chr(9) & "" & Chr(9) & "" & Chr(9) & ":-" & Chr(10) & "Total Order Value:" & Chr(9) & "" & Chr(9) & "" & Chr(9) & ":-" & Chr(10) & "" & Chr(10) & ""
varBody2 = "Please note that this is only an acknowledgement of your receipt of your order and your contract to purchase these items is not complete until we send you an order confirmation" & Chr(10) & "" & Chr(10) & "Attached is a copy of the Thermo Fisher Scientific General Terms and Conditions of Sale July 2010, which will apply to this order" & Chr(10) & "" & Chr(10) & "Please be aware that deliveries will be arranged to a ground floor warehouse/goods in, unless previously discussed and agreed with Thermo Fisher Scientific Area Account manager who coordinated this instrument purchase" & Chr(10) & "" & Chr(10) & "If a non-standard delivery is required (e.g. to a 1st floor laboratory) and is not included in the shipping of this instrument, please contact us and we can arrange a quotation from a specialist courier for you" & Chr(10) & "" & Chr(10) & "If you have any questions in the meantime please do not hesitate to contact us." & Chr(10) & "" & Chr(10) & "Kind Regards"




 'Body of the email


SendEmail varName, varSubject, varBody1 & varBody2, True


'Send email command. The True after "varBody" allows user to edit email before sending.
 'The False at the end will not send it as a Template File

End Function
 

StuartG

Registered User.
Local time
Today, 14:07
Joined
Sep 12, 2018
Messages
125
Yes, it was the one "automating" Outlook. All we need to do is pass the things it needs/requests to in-turn pass to Outlook to generate the email message.


This is good. We just need to modify it to use the new function now. For example, you could try:


Code:
Public Function SendEmail2()

Dim varName As Variant
Dim varCC As Variant
Dim varSubject As Variant
Dim varBody1 As Variant
Dim varBody2 As Variant


varName = ""
varCC = ""
'separate each email by a ','

varSubject = "Acknowledgement Of Receipt"
'Email subject

varBody1 = "Dear" & Chr(10) & "" & Chr(10) & "Thank you for your purchase order." & Chr(10) & "" & Chr(10) & "Customer Purchase Order Reference:" & Chr(9) & ":-" & Chr(10) & "Product Line Ordered:" & Chr(9) & "" & Chr(9) & "" & Chr(9) & ":-" & Chr(10) & "Quote Reference:" & Chr(9) & "" & Chr(9) & "" & Chr(9) & ":-" & Chr(10) & "Total Order Value:" & Chr(9) & "" & Chr(9) & "" & Chr(9) & ":-" & Chr(10) & "" & Chr(10) & ""
varBody2 = "Please note that this is only an acknowledgement of your receipt of your order and your contract to purchase these items is not complete until we send you an order confirmation" & Chr(10) & "" & Chr(10) & "Attached is a copy of the Thermo Fisher Scientific General Terms and Conditions of Sale July 2010, which will apply to this order" & Chr(10) & "" & Chr(10) & "Please be aware that deliveries will be arranged to a ground floor warehouse/goods in, unless previously discussed and agreed with Thermo Fisher Scientific Area Account manager who coordinated this instrument purchase" & Chr(10) & "" & Chr(10) & "If a non-standard delivery is required (e.g. to a 1st floor laboratory) and is not included in the shipping of this instrument, please contact us and we can arrange a quotation from a specialist courier for you" & Chr(10) & "" & Chr(10) & "If you have any questions in the meantime please do not hesitate to contact us." & Chr(10) & "" & Chr(10) & "Kind Regards"




 'Body of the email


SendEmail varName, varSubject, varBody1 & varBody2, True


'Send email command. The True after "varBody" allows user to edit email before sending.
 'The False at the end will not send it as a Template File

End Function
I am guessing your coding was the "SendEmail" bit at the end as the rest looks like what i typed, checked this and it did not work.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:07
Joined
Oct 29, 2018
Messages
21,357
Hi Stuart. You'll have to give us more to go on. What does "did not work" mean? Did you get an error? If so, what was the error message? You are correct, all I did was replaced the SendObject line with the call to Daniel's function (did I not spell it correctly?). I thought you said your code worked and you also said Daniel's function worked. So, I am not sure why simply combining the two wouldn't work. Perhaps you can post some screenshots or a sample copy of your db, so we can get to the bottom of this issue quicker.
 
Last edited:

StuartG

Registered User.
Local time
Today, 14:07
Joined
Sep 12, 2018
Messages
125
Hi Stuart. You'll have to give us more to go on. What does "did not work" mean? Did you get an error? If so, what was the error message? You are correct, all I did was replaced the SendObject line with the call to Daniel's function (did I not spell it correctly?). I thought you said your code worked and you also said Daniel's function worked. So, I am not sure why simply combining the two wouldn't work. Perhaps you can post some screenshots or a sample copy of your db, so we can get to the bottom of this issue quicker.

Hello DBguy,
Sorry I guess it helps, espicially to help diagnose the problem.
I received no error message it was more that it did not do what i had intended.

The code you asked me to write in the immediate using Daniels code worked, however it did not ask me to attach files which is what I wanted.

I attach a sample of my DB, which has a few examples in to use. I will explain the following:

There is a module called " Acknowledgement" this was a code written and is exactly the output that I am after, with the exception that it does not automatically attach a file (This is needed), this is the one that I have been having issues with.

There is a "Macro" called Email Test, this used the inbuilt functions of Access, however this does not allow me to attach multiple attachments, only the attachment of the report i created behind it. (Report called, Acknowledgement of Receipt)
I used this function also because it allowed me to map the existing fields in my DB without me creating some convoluted code.

I am unsure what is the best option here.
Ideally I would prefer to use the Acknowledgment code because it enables the user to edit the content of the email before sending, whereas the second option is dictated by the report i created.

Hope this helps?
Stuart
 

Attachments

  • Sales Database v5 TEST with Tables.zip
    1.1 MB · Views: 86

StuartG

Registered User.
Local time
Today, 14:07
Joined
Sep 12, 2018
Messages
125
Hello DBguy,
Sorry I guess it helps, espicially to help diagnose the problem.
I received no error message it was more that it did not do what i had intended.

The code you asked me to write in the immediate using Daniels code worked, however it did not ask me to attach files which is what I wanted.

I attach a sample of my DB, which has a few examples in to use. I will explain the following:

There is a module called " Acknowledgement" this was a code written and is exactly the output that I am after, with the exception that it does not automatically attach a file (This is needed), this is the one that I have been having issues with.

There is a "Macro" called Email Test, this used the inbuilt functions of Access, however this does not allow me to attach multiple attachments, only the attachment of the report i created behind it. (Report called, Acknowledgement of Receipt)
I used this function also because it allowed me to map the existing fields in my DB without me creating some convoluted code.

I am unsure what is the best option here.
Ideally I would prefer to use the Acknowledgment code because it enables the user to edit the content of the email before sending, whereas the second option is dictated by the report i created.

Hope this helps?
Stuart

Hi There,
OK, i have been doing some more research this morning and afternoon as the day to day at work has been rather slow.

Is there a way that I can link my database to attach a particular file (PDF) each time the user goes to send either and acknowledgment or confirmation?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:07
Joined
Oct 29, 2018
Messages
21,357
Hi Stuart. We can make the code do whatever we want, we just needed to know your ultimate goal. For example, how will the user initiate the action to send an acknowledgement or confirmation? Also, will the "particular PDF file" be the same every time?
 

StuartG

Registered User.
Local time
Today, 14:07
Joined
Sep 12, 2018
Messages
125
Hi Stuart. We can make the code do whatever we want, we just needed to know your ultimate goal. For example, how will the user initiate the action to send an acknowledgement or confirmation? Also, will the "particular PDF file" be the same every time?



Hi dbguy.
Ok, thanks.

So my ultimate goal is..
the user clicks a button this initiates “acknowledgment of receipt” it uses the report I created in access but then in addition to the form output it also attaches our terms and conditions.

Note the terms and conditions PDF never changes..

The form I created is dictated by the DB ID this then pulls al information for that record and populates the report.

Please note that in addition to this there will be multiple buttons doing the same thing, though the wording will be different in “order confirmation pdf” but I would still use the inbuilt email feature but each output must contain the Ts and Cs each time..

Hope that makes sense and i haven’t complicated it..

Stuart


Sent from my iPhone using Tapatalk
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:07
Joined
Oct 29, 2018
Messages
21,357
Okay, wherever this button is, write code behind it to construct the body of the email. To verify it, just use a MsgBox command. For example:


Code:
Dim strBody As String


strBody = "Dear " & Me.CustomerName & "," & vbCrLf & "Please see attached files."


MsgBox strBody
Once you have that, you can use Daniel's function to add attachments like so, assuming the file is located at c:\myfolder\myfile.pdf


Code:
SendEmail strTo, strSubject, strBody, True, , "c:\myfolder\myfile.pdf"
 

Users who are viewing this thread

Top Bottom