I code for sending multiple email through Outlook using Access database.
I want to search query by criteria for emails and the use these filter emails for sending email but I have the following problem with my VBA code:
"method not found" for "Query1.RecordCount
Private Sub outlook_Click()
Dim ooutlook As outlook.Application
Dim oEmailitem As outlook.MailItem
Dim rs As Recordset
Dim emaillist As String
Dim Query As String
Dim Query1 As QueryDef
If ooutlook Is Nothing Then
Set ooutlook = New outlook.Application
End If
Set oEmailitem = ooutlook.CreateItem(olMailItem)
With oEmailitem
Query = "QryStudentAddressDetails"
Set Query1 = CurrentDb.QueryDefs(Query)
If Query1.RecordCount > 0 Then
rs.MoveFirst
Do Until rs.EOF
If IsNull(rs![Email_Address]) Then
rs.MoveNext
Else
emaillist = emaillist & rs![Email_Address] & ";"
.To = emaillist
rs.MoveNext
End If
Loop
Else
`enter code here`MsgBox "No one has Email Address!"
End If
Set rs = Nothing
.CC = ""
.Subject = "testing email"
.Display
End With
Set oEmailitem = Nothing
Set ooutlook = Nothing
End Sub