Mike
I see you are not getting a Namespace or the default folder. That might be what is tripping you up. If Outlook is already open you wouldn't need those if I remember right.
Here is a snippet from my code. I'm using late-binding but I comment with the early-binding constants to make it easier to switch.
Dim objOLApp As Object 'Outlook.Application
Dim outItem As Object 'MailItem
Dim outFolder As Object 'MAPIFolder
Dim outNameSpace As Object 'NameSpace
Dim lngAttachment As Long
On Error GoTo err_Outlook_SendEmail
Set objOLApp = CreateObject("Outlook.Application")
Set outNameSpace = objOLApp.GetNamespace("MAPI")
Set outFolder = outNameSpace.GetDefaultFolder(6) 'olFolderInbox=6
Set outItem = objOLApp.CreateItem(0) 'olMailItem=0
outItem.Body = strMsg
outItem.Subject = strSubject
outItem.To = strTo
The full routine in on my website (http://thatlldoit.com/codesamples.aspx#anchor1 ) if you need it.
Bill
--- In MS_Access_Professionals@yahoogroups.com, mithomas48 <no_reply@...> wrote:
>
> Bill, here is the routine. All variables are loaded, but I'm not including an attachment so it is an empty string.
>
> 'Open Outlook.
> Set olApp = CreateObject("Outlook.Application")
> 'Open New Email.
> Set MailItem = olApp.CreateItem(olMailItem)
>
> With MailItem
> 'Repeat To and cc lines for each additional recipient.
> .To = sTO
> .cc = sCC
> .Subject = sSUBJ
> 'vbNewLine is used as a single line return to begin a new row.
> .Body = sBODY
> 'Assign attachments if needed. Otherwise, omit this line.
> 'Repeat this line for each additional attachment.
> If Not Nz(sATTACH, "") = "" Then
> .Attachments.Add (sATTACH)
> End If
> 'next line would let MS Outlook API send the note
> 'without storing it in your sent bin
> '.DeleteAfterSubmit = True
> .Send
> End With
>
> --- In MS_Access_Professionals@yahoogroups.com, "Bill Mosca" <wrmosca@> wrote:
> >
> > Mike
> >
> > using CreateObject should work even if Outlook is not open. It should only error out if Outlook is not installed.
> >
> > Care to share the entire routine? maybe something else needs fixing.
> >
> > Regards,
> > Bill Mosca, Founder - MS_Access_Professionals
> > http://www.thatlldoit.com
> > Microsoft Office Access MVP
> > https://mvp.support.microsoft.com/profile/Bill.Mosca
> >
> >
> >
> >
> > --- In MS_Access_Professionals@yahoogroups.com, mithomas48 <no_reply@> wrote:
> > >
> > > When sending an email, I noticed that even though I use a line to create an instance of Outlook, I get an Application or Object defined error if I DO NOT physically have Outlook open. Below is the syntax being used to create the instance of Outlook. Shouldn't we be able to create the object and send the email even if Outlook is not opened?
> > >
> > >
> > > Set olApp = CreateObject("Outlook.Application")
> > >
> > > Thanks in advance!
> > > Mike
> > >
> >
>
Selasa, 20 Maret 2012
[MS_AccessPros] Re: Outlook Error
__._,_.___
.
__,_._,___
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar