PC Review Forums Newsgroups Microsoft Outlook Microsoft Outlook VBA Programming RE: CreateItem - Operation Failed

Reply

RE: CreateItem - Operation Failed

 
Thread Tools Rate Thread
Old 21-12-2006, 05:07 AM   #1
=?Utf-8?B?Sktybw==?=
Guest
 
Posts: n/a
Default RE: CreateItem - Operation Failed


Sorry it took so long to get back to you. I was able to test this afternoon
while users were at lunch but I had to wait till they left for day to test
again.

Per your recommendation, it is now opening outlook and creating the email.
However, I am still getting the same errors on the same problematic pcs.
However I am getting one additional error on the pcs that get the Operation
Failed at line CreateItem. The error is:

An error has occurred while the following action was performed: Install
Forms. Description : Unspecified error.

This error is occuring on the line:

Set objExp = objOL.Explorers.Add(objNS.GetDefaultFolder(olFolderInbox),
olFolderDisplayNormal)

This error seems to only happen once then it goes away.

It seems my problems are not related to the code but rather something on the
pc. I thought maybe it was the version of outlook but I seem to have all
different versions and there are no correlations with the version and errors.

To summarize my testing thus far:

Some pcs have no problems at all with the code - it works fine if
outlook open or not.

Some pcs have problem only when outlook not already open. When close
the email object (because I put in display mode) the following error appears:
Microsoft Office Outlook has encountered a problem and needs to close.

Some pcs cannot even create the Email object, whether Outlook is open
or not. Those get Operation Failed on the following line of code: Set
objMail = objOL.CreateItem(olMailItem)

I appreciate the time you have spent thus far helping me to debug this. I
am at my wit's end because I have to release an update to my users which
includes this code and what's strange is, this code (or something similar to
it) worked fine on all my pcs just a few weeks ago. That is why I think it
is pc related - something changed on their pcs. We recently converted our
outlook to MS Exchange but why does this code work on some pcs and not
others...

Also, how can I find out if something is blocking scripting?




"Eric Legault [MVP - Outlook]" wrote:

> To clarify, an error on that line is expected if Outlook is not running, so
> add "On Error Resume Next" at the top. Does the code eventually open Outlook
> and send an e-mail?
>
> --
> Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
> Try Picture Attachments Wizard for Outlook:
> http://www.collaborativeinnovations.ca
> Blog: http://blogs.officezealot.com/legault/
>
>
> "JKro" wrote:
>
> > I tried the code that you supplied. It worked fine on one of the pcs that
> > was working properly before.
> >
> > I then tried it on the pc that was getting "Operation Failed" when executing
> > CreateItem and that pc received the following error:
> > ActiveX Component can't create object
> > at the line:
> > Set objOL = GetObject(, "Outlook.Application")
> >
> > I then tried it on the pc that was getting the MS Outlook error when closing
> > the email and I received the same error as before:
> >
> > Microsoft Office Outlook has encountered a problem and needs to close.
> > We are sorry for the inconvenience.
> >
> > Both pcs where I received errors, I tried again but first opened up Outlook
> > and the code worked fine then.
> >
> > Per your note, regarding the .Send method displaying a dialog asking the
> > user to allow an external app to send an e-mail. I downloaded "Advanced
> > Security for Outlook" which prevents these messages from coming up (sometimes
> > I need to programmatically email work tickets to hundreds of our vendors).
> >
> > "Eric Legault [MVP - Outlook]" wrote:
> >
> > > For funzies, try the code below from Access. Also note that the .Send method
> > > will display a dialog asking the user to allow an external app to send an
> > > e-mail.
> > >
> > > Dim objOL As Outlook.Application, blnNewOutlook As Boolean
> > > Dim objExp As Outlook.Explorer
> > > Dim objNS As Outlook.NameSpace
> > > Dim objMail As Outlook.MailItem
> > >
> > > 'Retrieve an existing Outlook Application object if it is already loaded
> > > Set objOL = GetObject(, "Outlook.Application")
> > > Err.Clear
> > > If objOL Is Nothing Then
> > > 'Outlook is closed; open it
> > > Set objOL = New Outlook.Application
> > > blnNewOutlook = True
> > > End If
> > > Set objNS = objOL.GetNamespace("MAPI")
> > >
> > > If blnNewOutlook = True Then
> > > Set objExp =
> > > objOL.Explorers.Add(objNS.GetDefaultFolder(olFolderInbox),
> > > olFolderDisplayNormal)
> > > objExp.Activate 'Show Outlook
> > > End If
> > >
> > > Set objMail = objOL.CreateItem(olMailItem)
> > > objMail.Subject = "test " & Date & " " & Time
> > > objMail.To = "user@mailserver.com"
> > > objMail.Send
> > >
> > > Set objMail = Nothing
> > >
> > > If blnNewOutlook = True Then
> > > objExp.Close
> > > objOL.Quit
> > > End If
> > >
> > > Set objExp = Nothing
> > > Set objNS = Nothing
> > > Set objOL = Nothing
> > >
> > > --
> > > Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
> > > Try Picture Attachments Wizard for Outlook:
> > > http://www.collaborativeinnovations.ca
> > > Blog: http://blogs.officezealot.com/legault/
> > >
> > >
> > > "JKro" wrote:
> > >
> > > > Hi Eric,
> > > >
> > > > Thank you so much for the advice.
> > > >
> > > > On the PC in question, I opened up the Outlook VBA editor and it bombed on
> > > > the same line:
> > > >
> > > > Set objMail = olApp.CreateItem(olMailItem)
> > > >
> > > > I also checked to see if there were any disabled items but there were not.
> > > >
> > > > How can I find out if something is blocking scripting?
> > > >
> > > > Also, I have tested this code on some other pcs (about 10 altogeter). On 5
> > > > pcs, it works successfully on. On 2 pcs, I get the error that I described
> > > > above. And on 3 pcs, the email is created and displayed but when I close the
> > > > email, they get the following error:
> > > >
> > > > Microsoft Office Outlook has encountered a problem and needs to close.
> > > > We are sorry for the inconvenience.
> > > >
> > > > The strange thing is, if I open up outlook prior to executing this code, it
> > > > works fine on all pcs. I thought this code would open up an instance of
> > > > outlook so I would not have to have Outlook running at the time of execution
> > > > (and this is the case on those 5 pcs where it works successfully).
> > > >
> > > > Am I missing something?
> > > >
> > > >
> > > >
> > > >
> > > > "Eric Legault [MVP - Outlook]" wrote:
> > > >
> > > > > Try again in the Outlook VBA editor on that PC to verify that Oultook can be
> > > > > automated. Use both CreateObject for the Application object, and the
> > > > > intrinsic Outlook.Application object.
> > > > >
> > > > > Also check under Help | About | Disabled Items just to make sure that the
> > > > > VBA Add-In isn't disabled.
> > > > >
> > > > > These are just guesses, as I was going to finger an anti-virus app as well.
> > > > > However, if scripting is blocked you will not be able to use CreateObject,
> > > > > but explicit late-bound references to the Outlook Object Model should work.
> > > > > If it does, something is blocking scripting.
> > > > >
> > > > > --
> > > > > Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
> > > > > Try Picture Attachments Wizard for Outlook:
> > > > > http://www.collaborativeinnovations.ca
> > > > > Blog: http://blogs.officezealot.com/legault/
> > > > >
> > > > >
> > > > > "JKro" wrote:
> > > > >
> > > > > > I have some code in an access database module that displays an email to send:
> > > > > >
> > > > > > Const olMailItem As Long = 0
> > > > > > Const olFormatPlain As Long = 1
> > > > > >
> > > > > > Dim olApp As Object
> > > > > > Dim objMail As Object
> > > > > >
> > > > > > Set olApp = CreateObject("Outlook.Application")
> > > > > > Set objMail = olApp.CreateItem(olMailItem)
> > > > > >
> > > > > > With objMail
> > > > > > .to = strEmail
> > > > > > .Subject = strSubject
> > > > > > .Body = strMessage
> > > > > > .attachments.Add (strAttachmentLocation)
> > > > > > .Display
> > > > > > End With
> > > > > >
> > > > > > Set objMail = Nothing
> > > > > > Set olApp = Nothing
> > > > > >
> > > > > > This code works fine on several pcs. However on at least one of my pcs, it
> > > > > > does not. The following line:
> > > > > >
> > > > > > Set objMail = olApp.CreateItem(olMailItem)
> > > > > >
> > > > > > Produces a run-time error, Operation Failed.
> > > > > >
> > > > > > All of the pcs are running Outlook 2003. The versions are slightly
> > > > > > different (successful pc: 11.5608.5606, unsuccessful pc: 11.5608.8107) but I
> > > > > > don't think its the version of outlook because alot of my successfull pcs
> > > > > > have slightly different versions.
> > > > > >
> > > > > > I checked the virus scan software and it is not blocking any outlook
> > > > > > scripting.
> > > > > >
> > > > > > I've been banging my head against a wall for 4 days now... I can't figure
> > > > > > out why this same code would fail on certain pcs (with no real clues as to
> > > > > > why.)
> > > > > >
> > > > > > Any help would be greatly appreciated!
> > > > > >
> > > > > >

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off