I have been trying to build an OnClick in Access VBA to send separate outlook emails with corresponding attachments from an Access query. I have found a bit of old code that I am trying to adapt.
This is for monthly invoice statements.
I have a parameter in the query to pull the exact attachments I need by date.
My query records start with a unique(Autonumb er) id, and includes the e-mail address and the path to the attachment, The attachment is on the same drive/network.
This is an example of a query record
STID CustID ACCT APCEmail STMTAP STDATE STMTPATH
30 740 999999 hmb@123.com TRUE 1/5/2019 C:\Users\Summar ies\EMAIL\99999 9.xlsx
My first problem is on Set rsEmail, runtime 3061 with two few parameters. Is this VBA correct to open a parameter query?
Thank you for any input so I can continue to test this.....
This is for monthly invoice statements.
I have a parameter in the query to pull the exact attachments I need by date.
My query records start with a unique(Autonumb er) id, and includes the e-mail address and the path to the attachment, The attachment is on the same drive/network.
This is an example of a query record
STID CustID ACCT APCEmail STMTAP STDATE STMTPATH
30 740 999999 hmb@123.com TRUE 1/5/2019 C:\Users\Summar ies\EMAIL\99999 9.xlsx
My first problem is on Set rsEmail, runtime 3061 with two few parameters. Is this VBA correct to open a parameter query?
Code:
Dim MyDb As DAO.Database
Dim rsEmail As DAO.Recordset
Dim sToName As String
Dim sSubject As String
Dim sMessageBody As String
Set MyDb = CurrentDb()
[B]Set rsEmail = MyDb.OpenRecordset("qrysendEMstmt", dbOpenSnapshot)
[/B]
With rsEmail
.MoveFirst
Do Until rsEmail.EOF
If IsNull(.Fields(3)) = False Then
sToName = .Fields(3)
sSubject = "SG Acct Summary: " & .Fields(2)
sMessageBody = ""Please find attached account summary for your reconciliation." & vbNewLine & "Kindly feedback payment status." & vbNewLine & "Thank you!"
DoCmd.SendObject acSendObject, , , _
sToName, , , sSubject, sMessageBody, False, False
End If
.MoveNext
Loop
End With
Set MyDb = Nothing
Set rsEmail = Nothing
Comment