none
Error setting outlook app var RRS feed

  • Question

  • We had a problem on one of our PC's with Office 2016 Pro and had to re-install Office.  Our Access application has email code that creates an email, attaches a PDF and sends it.  Since the re-install this code fails with the following error:

    Error 91: Object variable or With block variable not set.

    Below is a small part of code that is failing.  The error occurs on the line that sets the variable gOLApp. Has anyone run across this?

    Public gOLApp As Outlook.Application
    
        Set gOLApp = New Outlook.Application

    Tuesday, June 19, 2018 8:57 PM

All replies

  • Hi David,

    Did you go to Tools > References and verified if there's any reference marked missing?

    Just curious...

    Tuesday, June 19, 2018 9:06 PM
  • Is Outlook setup? You can manually open it, send/receive e-mails?

    Does your VBA project compile without errors?


    Daniel Pineault, 2010-2017 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net


    Wednesday, June 20, 2018 1:23 AM
  • Yes there is a reference to Outlook library.  I should also note that other users do not have errors with this application.
    Wednesday, June 20, 2018 3:50 PM
  • Yes, Outlook works fine.
    Wednesday, June 20, 2018 3:51 PM
  • Yes there is a reference to Outlook library.  I should also note that other users do not have errors with this application.

    Hi,

    Just to make sure we're on the same page... I forgot to mention, make sure to check the Outlook reference from the computer/user experiencing the problem.

    Hope it helps...

    Wednesday, June 20, 2018 3:55 PM
  • Yes, I did.
    Wednesday, June 20, 2018 3:57 PM
  • Yes, I did.

    Okay. Glad to hear that; however, sorry to hear it didn't help you. The next step, I think, is if you could share a sample copy of your db, we could check it out for you.

    Just a thought...

    Wednesday, June 20, 2018 4:11 PM
  • Sorry, it is not my database. It belongs to our client.
    Wednesday, June 20, 2018 5:46 PM
  • Sorry, it is not my database. It belongs to our client.

    Hi David,

    I can understand that. However, it might be possible to strip it down to the bare minimum objects affected by the issue (maybe down to one form and one module, or just one module). And it doesn't have to have any data or just add a couple of test data.

    If not, I am not sure what else to recommend at this point.

    Wednesday, June 20, 2018 6:09 PM
  • If it was an object or code issue then it would not work for all the other PC's.  This happened when Office 365/Access crashed and then Office 2016 was reinstalled.
    Wednesday, June 20, 2018 6:44 PM
  • If it was an object or code issue then it would not work for all the other PC's.  This happened when Office 365/Access crashed and then Office 2016 was reinstalled.

    Hi,

    What I was trying to get to is basically this. If you do not distribute compiled versions of your database, then each time a user opens the database on their machine, Access could modify the code (or more specifically, the reference library). Hence, asking to see a copy of the problem database file, could potentially show us something that is different than the working copies.

    Actually, come to think of it, try compiling a working copy of your database and then ask the user to run it on the problem computer to see if it works or not. Now, running compiled versions might not tell you about any issues unless you have a good error handling routine all over your code. If not, either your app will just continue to run but not function as expected or crash because of the error.

    Just my 2 cents...

    Wednesday, June 20, 2018 6:50 PM
  • They share the database on a network server.  The user created the initial database and we were contacted to maintain it and improve it. They did not create a "split" database (as I would have) so they are all using the same database file.

    My next step is to completely uninstall office on the problem computer and then do a re-install. It may be a dll registration issue or something.

    Wednesday, June 20, 2018 7:18 PM
  • Ouch, sorry to hear that. Good luck with Office repair. It sounds like a good plan. Please let us know how it goes. Good luck!
    Wednesday, June 20, 2018 7:28 PM
  • Completely removing office 2016 and installing again did nothing as the Error 91 continues!!!

    Could it have anything to do with the outlook profile?

    Friday, June 22, 2018 9:54 PM
  • Check to see if not the same issue reported in here:

    https://stackoverflow.com/questions/17364673/run-time-error-91-outlook-application-object-variable-or-with-block-varia

    Cheers,

    Vlad

    Friday, June 22, 2018 10:18 PM
  • Not the exact same issue.  That one is failing on the CreateItem event and the variable. Our error occurs prior to that when just setting the Outlook application variable as shown below.

    Public gOLApp As Outlook.Application

       
    Set gOLApp = New Outlook.Application

    The error 91 occurs on the Set line, apparently because it doesn't think Outlook app exists. However, there is no "missing" reference for Outlook as that appears to be ok.

    Wednesday, June 27, 2018 1:29 PM
  • Below is a summary of what we have tried and maybe it will jog an idea???

    1. User bought a new Dell PC with Office 365 pre-installed.

    2. Application worked fine for several weeks and still works fine for others.

    3. At startup one day the Office application went blank and clicking on any icon (Access, Outlook, Excel, etc.) did nothing.

    4. Called Dell and they ran integrity check on disk and all was fine.

    5. Dell Re-installed Office 2016 Pro and now there were 2 sets of Office icons. Old ones still did not work but new ones did.

    6. Tried application again but still got error 91.

    7. Removed all copies of Office and did a new Office install. Still got error 91.

    8. Tried creating new Outlook profile, restarted Outlook and Access still gave error 91.

    9. I am stumped!!!

    Wednesday, June 27, 2018 1:36 PM
  • Did you ever run the Debug...Compile menu option as suggested by .theDBGuy?

    I can't see your code (as posted) running without a syntax error. Is gOLApp defined at the module level or within a Sub or Function? Where is the Set statement located?

    As as alternative you can also try CreateObject:

    Set gOLApp = CreateObject("Outlook.Application")

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Wednesday, June 27, 2018 5:23 PM
  • gOLApp is defined at the module level. I tried the CreateObject but got the same error.

    Yes, I ran the compile.  Remember this runs fine on several other PC's. That is why I thought that the error had to do with something in Outlook.

    Wednesday, June 27, 2018 5:30 PM
  • Hi David,

    First of all, I like to say that you can prevent many problems by maintaining the Late Binding method as suggested by Paul. In that case you are not dependent on versions.

    Because it is not a split data database, this is a serious shortcoming.

    I understand that I do not offer a solution, but I want to point out these essential issues with which you can prevent problems in various situations.




    Wednesday, June 27, 2018 6:59 PM
  • Yes, my plan is to do something similar to below. I really wish the user would have me split the database so all users could run locally...but it is what it is.

                Dim olApp As New Outlook.Application
                Dim mItem As Outlook.MailItem  ' An Outlook Mail item
                
                Set olApp = CreateObject("Outlook.Application")
                Set mItem = olApp.CreateItem(olMailItem)
                ' Add the To/Subject/Body to the message and display or send the message
                With mItem
                    .Recipients.Add strTo
                    .Subject = strSubject
                    .Body = "Attached is your invoice"
                    .Attachments.Add stOutFile
                    If bolSend = True Then
                        .Send
                    Else
                        .Display    ' To show the email message to the user
                    End If
                End With
                
                ' Release all object variables
                Set mItem = Nothing
                Set olApp = Nothing
    

    Wednesday, June 27, 2018 7:17 PM
  • Hi David,

    If you use Late Binding, you need to declare variables as an Object (because in Late Binding you don't refer tot the library). Also you need to use constants for members of an object. If you need help, just let me know.

    Wednesday, June 27, 2018 7:58 PM
  • I tried the above code and it failed on the CreateObject line with "Error 429: ActiveX component can't create object"
    Wednesday, June 27, 2018 11:43 PM
  • Hi David,

    Here is the code from my global module. Use the following two procedures. (The comment is Dutch.)

    If you use this, you can use it for all Outlook actions. Place the code in a standard module.

    If you want to perform an action, call GetOutlook. When you're done with the action, call CleanUp.
    Tip: If you want to find the constants, you can find that in Outlook via the Object overview (F2).

    If you have any questions, let me know. It's late now, so I'm going to sleep. But tomorrow I'll be there for you if needed and I'll give a better explanation.

        Public olApp        As Object
        Public olNs         As Object

    Sub GetOutlook()

    On Error GoTo Bye_Err On Error Resume Next ' Initialiseer een sessie in Outlook. Set olApp = GetObject(, "Outlook.Application") If Err.Number = 429 Then 'App loopt niet. Set olApp = CreateObject("Outlook.Application") End If On Error GoTo 0 ' Retourneer een verwijzing naar de MAPI laag. Set olNs = olApp.GetNamespace("MAPI") olNs.Logon , , True, False ' Een test of is ingelogd. ' Debug.Print olNs.CurrentUser Bye_End: Exit Sub Bye_Err: MsgBox MsgErr, vbCritical, MT CleanUp Resume Bye_End End Sub Sub CleanUp() ' Maak geheugen van de object-variabelen vrij. Set olApp = Nothing Set olNs = Nothing End Sub



    Thursday, June 28, 2018 12:23 AM
  • gOLApp is defined at the module level. I tried the CreateObject but got the same error.

    Yes, I ran the compile.  Remember this runs fine on several other PC's. That is why I thought that the error had to do with something in Outlook.

    Just out of curiosity are all your Office apps 32-bit? 64-bit? 

    If you can't create an Outlook instance that leads me to believe that there is either a security issue or a configuration issue. If it's the later then I suspect your Registry is probably all fouled up from the installs, uninstall and re-installs. Also, if you have Office 2016 Pro then I would get rid of Office 365.

    I would also recommend looking in the Windows Event Log to see if any issues related to Outlook are being identified.


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Thursday, June 28, 2018 2:51 AM
  • Thanks Peter.  Hope you slept well.  Right now I am pursuing something other than a code problem since the same code works fine on all other users (and worked on this PC until system whacked out).

    I am leaning towards Paul's suggestion on the registry as the problem but have no idea where to look in the registry for problems in Outlook.

    Thursday, June 28, 2018 1:18 PM
  • Hi David,

    Yes, that's a good plan. Nevertheless, you also have to take into account that the problem can indeed be in code. Because if you make a reference to the Outlook library, every machine depends on the correct version. That can vary per machine.

    I wish you a lot of succes.

    Thursday, June 28, 2018 1:36 PM
  • Thanks Peter.  Hope you slept well.  Right now I am pursuing something other than a code problem since the same code works fine on all other users (and worked on this PC until system whacked out).

    I am leaning towards Paul's suggestion on the registry as the problem but have no idea where to look in the registry for problems in Outlook.

    Here's an easy one to check regarding security:

    https://social.msdn.microsoft.com/Forums/office/en-US/f8b3c4bd-e4b9-443e-9cd9-a28f33aea28c/activex-component-cant-create-object-access-vba-sending-email?forum=accessdev


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Thursday, June 28, 2018 6:10 PM
  • You could also try specifying the Outlook version number in the class library:

    https://social.msdn.microsoft.com/Forums/Lync/en-US/e6ebafda-14d4-44c4-acd5-3c3e030d57c4/cannot-create-activex-component?forum=outlookdev


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Thursday, June 28, 2018 6:21 PM
  • Still no luck.  The user account is admin account on this PC.

    By the way, this user cannot setup a "signature" in their Outlook mail options.  When they click the Signatures... button nothing happens. Not sure if this is related.  I still think it has something to do with this PC.

    Friday, June 29, 2018 12:03 AM
  • Still no luck.  The user account is admin account on this PC.

    By the way, this user cannot setup a "signature" in their Outlook mail options.  When they click the Signatures... button nothing happens. Not sure if this is related.  I still think it has something to do with this PC.

    Even admin accounts run with standard user permissions by default. This is part of UAC. They only run with admin permissions if the app is elevated (run as Administrator). I just wanted to make sure that Microsoft Access was not configured to "run as Administrator".


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Friday, June 29, 2018 12:18 AM
  • Neither are running as administrator. That box is unchecked.

    I found someone with similar problem and had to use a special Microsoft tool to completely remove everything associated with Office and then re-installed.  Has anyone ever done this?  Also, I do not want to lose the users email in 2 accounts.

    Friday, June 29, 2018 12:36 AM