A
Al
Hi can someone explain to me please what I am doing wrong.
the following code works down to the "With ObjMessage" line. The code then
returns an "Object variable or block variable not set". But have I not
declared tyhis already at the beginning?
Thanks
Al
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
Set rsEmailrecs = New ADODB.Recordset
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
the following code works down to the "With ObjMessage" line. The code then
returns an "Object variable or block variable not set". But have I not
declared tyhis already at the beginning?
Thanks
Al
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
Set rsEmailrecs = New ADODB.Recordset
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