Hi, I am brand new to the forum and was looking for some help with some code to automatically send emails out from an Access Customer Contacts Database. I am using Access and Outlook 2007 but the code needs to work with later versions of Access and Outlook.
I have very poor knowledge of coding and usually manage to cobble something together from looking at other code on the net but don't understand most of it.
I have the following code which works perfectly except I want to be able to embed an image in the email body (not have the image as an attachment but actually show it in the body of the email).
Most of the code I have found around this topic is too complex for me to understand and utilise within the context of the code I have.
Ideally I want to take the image from an attachment field in a table returned by the "tblMailingList_Query".
I have attached my current code and any help would be greatly appreciated.
I have very poor knowledge of coding and usually manage to cobble something together from looking at other code on the net but don't understand most of it.
I have the following code which works perfectly except I want to be able to embed an image in the email body (not have the image as an attachment but actually show it in the body of the email).
Most of the code I have found around this topic is too complex for me to understand and utilise within the context of the code I have.
Ideally I want to take the image from an attachment field in a table returned by the "tblMailingList_Query".
I have attached my current code and any help would be greatly appreciated.
Code:
[FONT=Calibri]Private Sub Command10_Click()[/FONT]
[FONT=Calibri] Dim MyDB As Database[/FONT]
[FONT=Calibri] Dim MyRS As Recordset[/FONT]
[FONT=Calibri] Dim objOutlook As Outlook.Application[/FONT]
[FONT=Calibri] Dim objOutlookMsg As Outlook.MailItem[/FONT]
[FONT=Calibri] Dim objOutlookRecip As Outlook.Recipient[/FONT]
[FONT=Calibri] Dim objOutlookAttach As Outlook.Attachment[/FONT]
[FONT=Calibri] Dim TheAddress As String[/FONT]
[FONT=Calibri] On Error Resume Next[/FONT]
[FONT=Calibri] Set MyDB = CurrentDb[/FONT]
[FONT=Calibri] Set MyRS = MyDB.OpenRecordset("tblMailingList_Query")[/FONT]
[FONT=Calibri] MyRS.MoveFirst[/FONT]
[FONT=Calibri] ' Create the Outlook session.[/FONT]
[FONT=Calibri] Set objOutlook = CreateObject("Outlook.Application")[/FONT]
[FONT=Calibri] Do Until MyRS.EOF[/FONT]
[FONT=Calibri] ' Create the e-mail message.[/FONT]
[FONT=Calibri] Set objOutlookMsg = objOutlook.CreateItem(olMailItem)[/FONT]
[FONT=Calibri] TheAddress = MyRS![EAddress][/FONT]
[FONT=Calibri] With objOutlookMsg[/FONT]
[FONT=Calibri] ' Add the To recipients to the e-mail message.[/FONT]
[FONT=Calibri] Set objOutlookRecip = .Recipients.Add(TheAddress)[/FONT]
[FONT=Calibri] objOutlookRecip.Type = olTo[/FONT]
[FONT=Calibri] ' Add the Cc recipients to the e-mail message.[/FONT]
[FONT=Calibri] If (IsNull(Forms!frmMail!CCAddress)) Then[/FONT]
[FONT=Calibri] Else[/FONT]
[FONT=Calibri] Set objOutlookRecip = .Recipients.Add(Forms!frmMail!CCAddress)[/FONT]
[FONT=Calibri] objOutlookRecip.Type = olCC[/FONT]
[FONT=Calibri] End If[/FONT]
[FONT=Calibri] ' Set the Subject, the Body, and the Importance of the e-mail message.[/FONT]
[FONT=Calibri] .Subject = Forms!frmMail!Subject[/FONT]
[FONT=Calibri] .Body = Forms!frmMail!MainText & vbCrLf & vbCrLf & Forms!frmMail!SecondText[/FONT]
[FONT=Calibri] .Importance = olImportanceHigh 'High importance[/FONT]
[FONT=Calibri] ' Resolve the name of each Recipient.[/FONT]
[FONT=Calibri] For Each objOutlookRecip In .Recipients[/FONT]
[FONT=Calibri] objOutlookRecip.Resolve[/FONT]
[FONT=Calibri] If Not objOutlookRecip.Resolve Then[/FONT]
[FONT=Calibri] objOutlookMsg.Display[/FONT]
[FONT=Calibri] End If[/FONT]
[FONT=Calibri] Next[/FONT]
[FONT=Calibri] .Send[/FONT]
[FONT=Calibri] End With[/FONT]
[FONT=Calibri] MyRS.MoveNext[/FONT]
[FONT=Calibri] Loop[/FONT]
[FONT=Calibri] Set objOutlookMsg = Nothing[/FONT]
[FONT=Calibri] Set objOutlook = Nothing[/FONT]
[FONT=Calibri][FONT=Calibri]End Sub[/FONT]
[/FONT]