Sorry, me again! I picked up the following very useful-looking bit of code from this site somewhere a while back. Now having need of something like it I decided to try it out. I can fully understand what it's doing, and so expected that it would work. But it hit a problem. The code is ...
I have set a reference to the Outlook 12.0 object library, as per the initial comment.
The code halts at the line .Send, with the message "Applicatio n defined or Object defined error" which, in this case, presumably means Outlook doesn't like it.
Can anyone help me out with this?
Code:
Private Sub Command0_Click()
'First, make sure that you have a Reference set to the
'Microsoft Outlook XX.X Object Library.
'Assuming you have a Table named tblEMailAddress, and it contains
'a Field to hold the E-Mail Addresses named [EAddr] :
Dim strEMail As String
Dim oOutlook As Object
Dim oMail As Object
Dim strAddr As String
Dim MyDB As DAO.Database
Dim rstEMail As DAO.Recordset
Set oOutlook = CreateObject("Outlook.Application")
Set oMail = oOutlook.CreateItem(0)
'Retrieve all E-Mail Addressess in tblEMailAddress
Set MyDB = CurrentDb
Set rstEMail = MyDB.OpenRecordset("TEST_EMAIL_TBL", dbOpenSnapshot, dbOpenForwardOnly)
With rstEMail
Do While Not .EOF
'Build the Recipients String
strEMail = strEMail & ![EAddr] & ";"
.MoveNext
Loop
End With
'--------------------------------------------------
With oMail
.To = Left$(strEMail, Len(strEMail) - 1) 'Remove Trailing ;
.Body = "Test E-Mail to Multiple Recipients"
.Subject = "Yada, Yada, Yada"
[B] .Send[/B] 'code halts here with error message
End With
Set oMail = Nothing
Set oOutlook = Nothing
rstEMail.Close
Set rstEMail = Nothing
End Sub
The code halts at the line .Send, with the message "Applicatio n defined or Object defined error" which, in this case, presumably means Outlook doesn't like it.
Can anyone help me out with this?
Comment