[AccessD] Outlook Automation

Rocky Smolin rockysmolin2 at gmail.com
Thu Mar 21 20:06:50 CDT 2024


Dan:

I can't use olMailItem because I'm using late binding. So until run time
the comp doesn't know the properties and methods of the outlook object. So
inserting olMainItem throws an undefined variable error. However olMailItem
is an Outlook constant and its value is zero.

If I can't figure this out, I'll switch to early binding and any client
that uses the app without having outlook installed will get a broken
reference error when they try to run the app.

At the start of the module to create an email I have

    If CheckOutlook = False Then
        MsgBox "Outlook is not installed on this machine.  Import
cancelled.", vbCritical
        Exit Sub
    End If

where CheckOutlook returns false if it's not installed:

Function CheckOutlook() As Boolean

Dim MiObj As Object

On Error Resume Next

    Set MiObj = CreateObject("Outlook.Application")

    If Err.Number <> 0 Then
        CheckOutlook = False
    Else
        CheckOutlook = True
    Set MiObj = Nothing

    End If

On Error GoTo 0

End Function


Just trying to make the app a little more user friendly. --> No good deed
goes unpunished. :o)

r

On Thu, Mar 21, 2024 at 4:48 PM Daniel Waters <df.waters at outlook.com> wrote:

> In https://learn.microsoft.com/en-us/office/vba/api/outlook.mailitem the
> way to set up an Outlook Item is
>
>         Set myItem = Application.CreateItem(olMailItem)
>
>         Your code is:
>         Set myItem = Application.CreateItem(0)
>
> Also:
> .Recipients would be for display names:
> Set myRecipient = myItem.Recipients.Add ("Jon Grande")
>
> -----Original Message-----
> From: AccessD <accessd-bounces+df.waters=outlook.com at databaseadvisors.com>
> On Behalf Of Rocky Smolin
> Sent: 21 March, 2024 18:07
> To: Access Developers discussion and problem solving <
> accessd at databaseadvisors.com>
> Subject: Re: [AccessD] Outlook Automation
>
> Oops - forgot to add these two lines to my post:
>
>     Set myolApp = CreateObject("Outlook.Application")
>     Set myItem = myolApp.CreateItem(0)
>
> Those are probably important :o)
>
> Late Binding BTW.
>
> Thanks
>
> r
>
> On Thu, Mar 21, 2024 at 4:04 PM Daniel Waters <df.waters at outlook.com>
> wrote:
>
> > Hi Rocky,
> >
> > Have you set the variables to the Outlook App itself?  Look back in
> > the code you cribbed from to find those.
> >
> > HTH!
> > Dan
> >
> > -----Original Message-----
> > From: AccessD
> > <accessd-bounces+df.waters=outlook.com at databaseadvisors.com>
> > On Behalf Of Rocky Smolin
> > Sent: 21 March, 2024 17:52
> > To: Access Developers discussion and problem solving <
> > accessd at databaseadvisors.com>
> > Subject: [AccessD] Outlook Automation
> >
> > Dear List:
> >
> > I am trying to create an email through Automation using late binding
> > (in case the target machine does not have access loaded; I check for
> > that first and bail if no outlook).
> >
> > My DIMs:
> >
> > Dim myolApp As Object
> > Dim myItem As Object
> >
> > Code:
> > myItem.To = Me.fldTenantEmail
> > myItem.cc = "Kathy.Klein at arensgroup.com"
> > myItem.Subject = "Rent Increase Notice - " & Me.fldTenantCompany & " -
> > " & me.fldTenantAddress & ", " & Me.fldTenantSuiteNumber
> >
> > The lines for .Subject and .CC work but Myitem.To fails with Method 'To'
> > of object '_MailItem' failed.
> >
> > Me.fldTenantEmail contains Armando at fallbrookirrigation.com
> >
> > If I substitute xx for Armando at fallbrookirrigation.com then it works.
> > I'm thinking it may have something to do with the special characters?
> >
> > But I have cribbed this code from another app that works.
> >
> > Any ideas?
> >
> > MTIA
> >
> > Rocky
> > --
> > AccessD mailing list
> > AccessD at databaseadvisors.com
> > https://databaseadvisors.com/mailman/listinfo/accessd
> > Website: http://www.databaseadvisors.com
> > --
> > AccessD mailing list
> > AccessD at databaseadvisors.com
> > https://databaseadvisors.com/mailman/listinfo/accessd
> > Website: http://www.databaseadvisors.com
> >
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>


More information about the AccessD mailing list