Attach specific file as attachment based upon dropdown value

Worsty

Board Regular
Joined
Jun 29, 2004
Messages
183
I've got this code in my access database behind a button. What I want to be able to do is to have it look for the value in the dropdown and based on the value attach a .pdf file to the email upon execution. Can you help me out with this. I've got it pretty much on its way, it just needs a little tweeking...

Private Sub Command4_Click()
On Error GoTo Err_Command5_Click
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem

Dim MyBodyText As String
Dim frm As Form
Dim ctl As Control
Dim varItem As Variant
Dim strSql As String
Dim myattachments As Variant
Dim lItemCount As Long
Dim mailStationery As String

'send email with spreadsheet

Set MyOutlook = New Outlook.Application
Set MyMail = MyOutlook.CreateItem(olMailItem)



MyMail.To = "jwsullivan@gaic.com"
MyMail.CC = ""
MyMail.BCC = Text1
MyMail.BodyFormat = olFormatHTML

MyMail.Subject = "Monthly Newsletter"
MyBodyText = "Here is the document"
Set myattachments = MyMail.Attachments
myattachments.Add "C:\JetComp.doc"
MyMail.SentOnBehalfOfName = "Great American SHS NonProfit"

'******************************************************
'put the HTML code for the stationery to a variable and then assign
'it to the HTMLBody
If Combo16.Value = "Newsletter" Then
mailStationery = ""
mailStationery = mailStationery & ""
mailStationery = mailStationery & ""
mailStationery = mailStationery & ""
mailStationery = mailStationery & "
"
mailStationery = mailStationery & "
"
mailStationery = mailStationery & "
"


Else
mailStationery = ""
End If
'******************************************************
MyMail.HTMLBody = mailStationery
'MyMail.HTMLBody = "My HTML Background" & _
""

MyMail.Display

Set MyMail = Nothing
Set myattachments = Nothing
Set MyOutlook = Nothing
Exit_Command5_Click:
Exit Sub

Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click

End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,215,274
Messages
6,123,995
Members
449,137
Latest member
abdahsankhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top