A
Al
Hi Could someone tell me what is wrong with the code below. I am getting
an error 91 at line startingt rsEmailrecs.Open
Thanks
Public Sub Email()
Dim rsEmailrecs As ADODB.Recordset
Dim objOutlook As New Outlook.Application
Dim objMessage As MailItem
Dim strMessage As String
Dim strSQL As String
rsEmailrecs.Open "QryFollowUp", CurrentProject.Connection
With rsEmailrecs
While Not rsEmailrecs.EOF
strMessage = "Dear " & rsEmailrecs(("Title") & " " & ("Surname")) &
_
vbCrLf & vbCrFl & _
"test text"
If Not IsNull(rsEmailrecs("tblContacts.email")) Then
With objMessage
.to = "name@domain"
.Subject = "Subject Line here"
.body = strMessage
.send
End With
End If
rsEmailrecs.MoveNext
Wend
End With
'rsEmailrecs.Close
'Set rsEmailrecs = Nothing
'Set objOutlook = Nothing
'Set objMessage = Nothing
End Sub
an error 91 at line startingt rsEmailrecs.Open
Thanks
Public Sub Email()
Dim rsEmailrecs As ADODB.Recordset
Dim objOutlook As New Outlook.Application
Dim objMessage As MailItem
Dim strMessage As String
Dim strSQL As String
rsEmailrecs.Open "QryFollowUp", CurrentProject.Connection
With rsEmailrecs
While Not rsEmailrecs.EOF
strMessage = "Dear " & rsEmailrecs(("Title") & " " & ("Surname")) &
_
vbCrLf & vbCrFl & _
"test text"
If Not IsNull(rsEmailrecs("tblContacts.email")) Then
With objMessage
.to = "name@domain"
.Subject = "Subject Line here"
.body = strMessage
.send
End With
End If
rsEmailrecs.MoveNext
Wend
End With
'rsEmailrecs.Close
'Set rsEmailrecs = Nothing
'Set objOutlook = Nothing
'Set objMessage = Nothing
End Sub