I am trying to adapt the following code and it errors out in the highlighted row. I am not familiar with the syntax to set a DAO recordset could someone point me in the right direction or correct what I have.
Thanks
Private Sub btnEmail_Click()
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim strEMailMsg As String
Dim strAttachmentPath As String
Dim rsATT As DAO.Recordset
Dim db As Database
Set db = CurrentDb()
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
strEMailMsg = "Attached..........."
.Subject = "Invoice Number" & [Invoice_Number]
.body = strEMailMsg
Set rsATT = CurrentDb.OpenRecordset("Invoice Query").Fields("Invoice_Attachments")
If rsATT.BOF And rsATT.EOF Then
GoTo noAttach
Else
Do Until rsATT.EOF
strAttachmentPath = rsATT.Fields("FilePath")
.Attachments.Add (strAttachmentPath)
rsATT.MoveNext
Loop
End If
noAttach:
.Display
End With
Set rsATT = Nothing
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
Invoice Query is the dataset for the Form and the field name is Invoice_attachments. I get the error "Type Mismatch". The goal is to email all of the attachments related to an invoice.