Avatar of MitchellVII
MitchellVIIFlag for United States of America

asked on 

Just switched to Vista, getting dreaded 429 (ActiveX) Error when automating Outlook from Access.

Hi,

I have some code which I have been using for years under Windows XP and Office 2003 that automated Outlook from Access.  It has always worked, but now that I have upgraded to Vista and Outlook 2007 (still using Access 2003), I am getting a "429 Error: ActiveX component can't create object" when I try to run the code.

Here is the code, if any experts can point out what needs to be changed I would greatly appreciate it:

Public Function fSendMessage(vForm As Form, vDisplayMsg, vIDOptions As String)
Dim objOutlook As Object
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim dbs As Database
Dim rst As Recordset
Dim vPostID As Long
Dim OrgStr As String
Dim NewStr As String
Dim Position As String
Dim Word As String
Dim sql As String
Dim vWhere As String

'Set vWhere Variable:
Select Case vIDOptions
    Case "Active"
        vWhere = "(((SummaryPost.PostStatus)='Send') AND ((SummaryPost.ID)=" & vForm.Controls("ID") & "))"
    Case "All"
        vWhere = "(((SummaryPost.PostStatus)='Send'))"
    Case Else
        vWhere = "(((SummaryPost.PostStatus)='Send') AND ((SummaryPost." & vIDOptions & "ID)=" & vForm.Controls(vIDOptions & "ID") & "))"
End Select

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT SummaryPost.* " _
                            & "FROM SummaryPost " _
                            & "WHERE " & vWhere & ";", DB_OPEN_DYNASET)

Do Until rst.EOF

    'Create the Outlook session.
    Set objOutlook = CreateObject("Outlook.Application")

    'Create the message.
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

    With objOutlookMsg

        'Add the To recipient(s) to the message.
        If Not IsNull(rst![PostAddressTo]) Then
            Set objOutlookRecip = .Recipients.Add(rst![PostAddressTo])
            objOutlookRecip.Type = olTo
        End If

        'Add the Cc recipient(s) to the message.
        If Not IsNull(rst![PostAddressCc]) Then
            Set objOutlookRecip = .Recipients.Add(rst![PostAddressCc])
            objOutlookRecip.Type = olCC
        End If

        'Add the Bcc recipient(s) to the message.
        If Not IsNull(rst![PostAddressBcc]) Then
            Set objOutlookRecip = .Recipients.Add(rst![PostAddressBcc])
            objOutlookRecip.Type = olBCC
        End If

        'Set the Subject, Body, and Importance of the message.
        If Not IsNull(rst![PostSubject]) Then
            .Subject = rst![PostSubject]
        End If

        If Not IsNull(rst![PostMessage]) Then
            .HTMLBody = "<div style='font-family:" & vForm.Controls("PostMessageFont") & ";font-size:" & vForm.Controls("PostMessageSize") & "'>" & Replace(vForm.Controls("PostMessage"), vbLf, "<br>") & "</div>"
            '        .Body = rst![PostMessage] & fCR1() & vbCrLf
        End If
        .Importance = olImportanceHigh  'High importance

        'Add attachments to the message.
        If Not IsNull(rst![PostAttachFile]) Then
            OrgStr = Trim(CStr(rst![PostAttachFile])) & " "
            NewStr = OrgStr

            Do Until Len(NewStr) <= 0
                Position = InStr(1, NewStr, " ")
                Word = Left(NewStr, Position - 1)

                Set objOutlookAttach = .Attachments.Add(Word)

                NewStr = LTrim(Right(NewStr, Len(NewStr) - (Len(Word) + 1)))
            Loop
        End If

        'Resolve each Recipient's name.
        For Each objOutlookRecip In .Recipients
            objOutlookRecip.Resolve
        Next

        'Should we display the message before sending?
        If vDisplayMsg Then
            .Display
        Else
            .Send
        End If

    End With

    Set objOutlook = Nothing
    rst.Edit
    rst![PostDate] = fDateMedium()
    rst![PostStatus] = "Sent"
    rst.Update
    rst.MoveNext
Loop
rst.Close
End Function
Microsoft Access

Avatar of undefined
Last Comment
Scott McDaniel (EE MVE )
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

First, have you verified that your references are in proper shape? Open your Access application, open the Edit window, then click Tools - References and make sure nothing is marked as MISSING. If it is you'll need to remake that reference.

If that doesn't work, can you pinpoint the line where your error occurs?
Avatar of MitchellVII
MitchellVII
Flag of United States of America image

ASKER

Hey LSM,

Yes, all references are proper.  The error seems to be starting here:

Dim objOutlook As Object
Dim objOutlookMsg As Outlook.MailItem  <<< RIGHT HERE!
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

Maybe it is because I am using Access 2003 and Outlook 2007?  Maybe the "As Outlook.MailItem" needs to be different for Outlook 07?  
Avatar of MitchellVII
MitchellVII
Flag of United States of America image

ASKER

LSM,

Here is something odd:

I went to MS and got the following code for automating Tasks with Outlook 2007.  When I try to run the code, I get a "Type Mismatch" error, which is weird as it should work.  Here is the code:

Sub CreateNewDefaultOutlookTask()
    Dim objOLApp As Outlook.Application
    Dim NewTask As Outlook.TaskItem
    ' Set the Application object
    Set objOLApp = New Outlook.Application
    ' You can only use CreateItem for default items
    Set NewTask = objOLApp.CreateItem(olTaskItem)  << Type Mismatch Error here!
    ' Display the new task form so the user can fill it out
    NewTask.Display
End Sub

What do you think?
Avatar of MitchellVII
MitchellVII
Flag of United States of America image

ASKER

Oh, one last thing.  this is just a "trial" version of Outlook 2007.  I doubt that could be causinga  rpoblem, but you never know.
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo