Object problems - help needed please

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
 
R

Ron Weiner

Al

Set objMail = objOutlook.CreateItem(olMailItem)

Somewhere before the With ObjMessage line but after instantiating objOutlook

Ron W
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top