Using ACCESS, WORD and OUTLOOK to send bulk E-Mails (3 Viewers)

LarryE

Well-known member
Local time
Today, 13:51
Joined
Aug 18, 2021
Messages
1,049
Code:
Dim olApp As Object
Set olApp = CreateObject("Outlook.Application")

causes this error to occur:
1758552090144.png

I DO have Microsoft Outlook 16.0 Object Library reference checked.

I have not a clue what this error message is. Do You?

Also, as the subject line suggests, I am attempting to send bulk e-mails to recipients (E-mail addresses stored as text in an ACCESS table) with a WORD document as the e-mail body and OUTLOOK as the vehicle to send them. Maybe I'm just nuts.
 
I have not a clue what this error message is. Do You?
Not from what you are showing. If you defined a constant with the CONST keyword and then tried to reassign a value you would get that error, but that is not what you are doing. So I guess it is a bogus error message. Sometimes when things do not compile you can get weird errors. I would delete the module and recompile. Then add the module back and re do it. Assuming this is not in your form's module.
 
This is an "I'm sorry but I have to ask" question. Are you using new or old outlook? Anyone can check the library, but I don't know that NEW outlook even cares.
 
If you are using "new" (web based outlook) you have bigger problems than that.
 
To clarify, you cannot automate New Outlook from Access or any other Office app.
Either revert to 'classic' Outlook or use CDO to send your email direct from Access bypassing Outlook completely.
 
Not from what you are showing. If you defined a constant with the CONST keyword and then tried to reassign a value you would get that error, but that is not what you are doing. So I guess it is a bogus error message. Sometimes when things do not compile you can get weird errors. I would delete the module and recompile. Then add the module back and re do it. Assuming this is not in your form's module.
Code:
Private Sub SendBulkEmails_Click()
    On Error GoTo BuilkError
    Dim db As DAO.Database, rs As DAO.Recordset
    Dim wdApp As Object, wdDoc As Object
    Dim olApp As Object, olMail As Object
    Dim emailBody As String
    Dim wordPath As String
    Dim tempBody As String
    wordPath = "C:\Users\larry\OneDrive\Documents\SCSHBulkEMailTemplate.docx"
    Set db = CurrentDb
    Set rs = db.OpenRecordset("E_Mail_Blast")
    Set wdApp = CreateObject("Word.Application")
    Set wdDoc = wdApp.Documents.Open(wordPath, False, True) ' Read-only
    Set olApp = CreateObject("Outlook.Application")
    Do While Not rs.EOF
        ' Replace placeholders
        tempBody = wdDoc.Content.Text
        Set olMail = olApp.CreateItem(0)
        With olMail
            .To = Me.MailAddress
            .Subject = Me.Subject
            .Body = tempBody
            .Send ' Use .Display for testing
        End With
        rs.MoveNext
    Loop
    wdDoc.Close False
    wdApp.Quit
    rs.Close
    Set rs = Nothing
    Set db = Nothing
    Set wdDoc = Nothing
    Set wdApp = Nothing
    Set olMail = Nothing
    Set olApp = Nothing
Exit Sub
BuilkError:
MsgBox Err.DESCRIPTION
Exit Sub
End Sub
This is the complete CoPilot AI generated code. When I step through it, ACCESS completely crashes at:
Set olApp = CreateObject("Outlook.Application")
so I have to use Task Manager to close ACCESS.

I don't think OutLook is compatible with ACCESS and WORD. I can reference the WORD document and create the object fine, but the OutLook object is another matter apparently.
 

New Outlook does NOT support COM automation. You will need to revert to old Outlook for use something else like Microsoft Graph.

Your code snip is using late binding, so checking "Microsoft Outlook 16.0 Object Library" does nothing for your code. It may also be the source of your error if using new Outlook. Try unchecking it then decompile / compact repair / compile.
 
New Outlook does NOT support COM automation. You will need to revert to old Outlook for use something else like Microsoft Graph.

Your code snip is using late binding, so checking "Microsoft Outlook 16.0 Object Library" does nothing for your code. It may also be the source of your error if using new Outlook. Try unchecking it then decompile / compact repair / compile.
OK I thought so. All this is just an experiment anyway.
 
To me the error is still strange. If I try to create and object that I cannot create I would expect this.
not expected.PNG

I should get that error when I do this.
expected.PNG
 
To me the error is still strange. If I try to create and object that I cannot create I would expect this.
View attachment 121579
I should get that error when I do this.
View attachment 121580
Yeah, when I asked CoPilot what my error message meant, it said i tried to define a constant as Dim instead of Const, but of course I did define it as Dim, but I didn't get the ActiveX error, I got the Assignment error. WAAAAAAAAY over my head, I am glad maybe someone can understand it.
 

Users who are viewing this thread

Back
Top Bottom