Hi,
I want to make a button, that starts sending out emails based on a query. I dont want the Query to be in the vba script itself, but I want the button to open a query first, then based on that results I want to start sending mails.
The query uses a popup, when i click the query it opens a popup field and I can type the last name. When i press enter I get all results based on that last name.
I want to make the mail button work the same way. When I click it, i want the query popup to show and when I type the last name and press enter, i want to mail all those based on the query results.
I managed to get the mailscript working, however it always gets all the persons in the table instead of the query results, any idea what I am doing wrong?
Current code that works, but not with a query:
Thanks in advance!
I want to make a button, that starts sending out emails based on a query. I dont want the Query to be in the vba script itself, but I want the button to open a query first, then based on that results I want to start sending mails.
The query uses a popup, when i click the query it opens a popup field and I can type the last name. When i press enter I get all results based on that last name.
I want to make the mail button work the same way. When I click it, i want the query popup to show and when I type the last name and press enter, i want to mail all those based on the query results.
I managed to get the mailscript working, however it always gets all the persons in the table instead of the query results, any idea what I am doing wrong?
Current code that works, but not with a query:
Code:
Dim MyDB As DAO.Database
Dim rst As DAO.Recordset
Dim strEMail As String
Dim strSubject As String
Dim strBody As String
Dim stDocName As String
Set MyDB = CurrentDb
Set rst = MyDB.OpenRecordset("table1", dbOpenForwardOnly)
With rst
Do While Not .EOF
strEMail = ![Emailadres] & ";"
strSubject = "Subject Title Mail"
strBody = "Test1 " & ![lastname] & "," & vbCrLf & _
"" & vbCrLf & _
"Text2" & vbCrLf & _
"" & vbCrLf & _
"Text3" & vbCrLf & _
"" & vbCrLf & _
"Text4," & vbCrLf & _
"" & vbCrLf & _
"Text5"
DoCmd.SendObject , , , strEMail, , , strSubject, strBody
.MoveNext
Loop
End With
rst.Close
Set rst = Nothing
Thanks in advance!