I am trying to automate a command button in a user form to send two reports in the On Click event. The first report is a txt file created by other software that will write a text file to My Documents. The second report is an Access report created when the user inputs some data. I am getting a compile error "Expected End Sub" when I run this event.
Private Sub cmdTest_Click()
Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Alan D")
objOutlookRecip.Type = olTo
' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "This is the body of the message." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add("C:\MyDocuments\EmailAutomationCodeX.txt")
Set objOutlookAttach = .Attachments.Add("C:\mdb\Report")
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
' Should we display the message before sending?
If DisplayMsg Then
Set objOutlook = Nothing