Hey all,
I am attempting to have an On_Click event call a public sub to attach all the .pdfs stored in a query directly to an email. I keep getting a Too few parameters and I am unsure as to why, I have tried multiple ways to fix this, including different ways of pulling the records needed. In the end I found a block of code on the forums that was reported to work, that I understand well, and was exactly what I needed. For some reason that is also giving me too few parameters. Please find a redacted version of the code below. The error appears to occur on the Set pBioAttachments line.
I am attempting to have an On_Click event call a public sub to attach all the .pdfs stored in a query directly to an email. I keep getting a Too few parameters and I am unsure as to why, I have tried multiple ways to fix this, including different ways of pulling the records needed. In the end I found a block of code on the forums that was reported to work, that I understand well, and was exactly what I needed. For some reason that is also giving me too few parameters. Please find a redacted version of the code below. The error appears to occur on the Set pBioAttachments line.
Code:
Option Compare Database
Option Explicit
Public Sub SendBio(MessageBody As String, RecipientEmail As String, Subject As String, AttachmentFile As String)
Dim O As Outlook.Application
Dim M As Outlook.MailItem
Dim objOutlookAttach As Outlook.Attachment
Set O = New Outlook.Application
Set M = O.CreateItem(olMailItem)
With M
.BodyFormat = olFormatHTML
.HTMLBody = MessageBody
.To = RecipientEmail
.CC = "email3@email.com"
.BCC = "email@email.com; email2@email.com"
.Subject = Subject
.Attachments.Add AttachmentFile
.SentOnBehalfOfName = "email3@email.com"
Dim db As DAO.Database
Dim pBioAttachments As DAO.Recordset
Set db = CurrentDb()
Set pBioAttachments = db.OpenRecordset("Select [FIELD NAME] from QUERYNAME")
If pBioAttachments.RecordCount > 0 Then
With pBioAttachments
Do Until .EOF
O.Attachments.Add (pBioAttachments![FIELD NAME])
.MoveNext
Loop
End With
End If
.Save
.Display
End With
Set M = Nothing
Set objOutlookAttach = Nothing
Set O = Nothing
Set pBioAttachments = Nothing
Set db = Nothing
End Sub
Last edited: