Help with the code

Markvand

Registered User.
Local time
Today, 21:21
Joined
Jul 13, 2004
Messages
88
What I'm trying to do is to sent an email to group of users (getting addresses from the query) without using Outlook (sending directly through SMTP server)

I use the following code and I get the following error: Runtime error "91", Object Variable or With block variable not set,
CDO Library is referenced


Dim StrSearch As String
Dim rsEmail As DAO.Recordset
Dim strEmail As String
Dim iMsg
Dim iConf
Dim Flds
Dim strHTML

Set rsEmail = CurrentDb.OpenRecordset("INQ_EMail")

' Send by connecting to port 25 of the SMTP server.

Const cdoSendUsingPort = 2

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")

Set Flds = iConf.Fields

' Set the CDOSYS configuration fields to use port 25 on the SMTP server.

With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
'ToDo: Enter name or IP address of remote SMTP server.
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "intranet"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
.Update
End With

' Build HTML for message body.
strHTML = "<HTML>"
strHTML = strHTML & "<HEAD>"
strHTML = strHTML & "<BODY>"
strHTML = strHTML & "<b> </b></br>"
strHTML = strHTML & "</BODY>"
strHTML = strHTML & "</HTML>"

Do While Not rsEmail.EOF
strEmail = rsEmail.Fields("Email").Value

' Apply the settings to the message.
With iMsg
Set .Configuration = iConf
.To = strEmail 'ToDo: Enter a valid email address.
.From = StrSearch 'ToDo: Enter a valid email address.
.Subject = "Test"
.HTMLBody = "Test"
.Send
End With

' Clean up variables.
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing

rsEmail.MoveNext

Loop
Set rsEmail = Nothing

MsgBox "Emails have been sent"


End Sub


Any ideas?

Cheers

Mark
 
I found out that the problem is with the loop, it sends email only to first user from a query list, end shows the error after.

Still trying to solve that puzzle, thus help would be great!
 
Can anybody help me with this, please?
 

Users who are viewing this thread

Back
Top Bottom