Error Wih GetNameSpace

John Clingeleffer
John Clingeleffer used Ask the Experts™
on
Hello Experts,

The following code snippet (I have not included the whole function) runs from MS Access to text if a user can get to their Outlook inbox. Works across any Access from 2003 to 2010 and with any Outlook from 2003 to 2010. Which version of Access are combined with which versions of Outllok alsodoen't seem to matter as long as references point to the right Outlook version. On one computer (of hundreds) which has Access 2003 and Outlook 2010 the code fails at the highlighted GetNamespace line. Any ideas?

John

Dim outlookForceStarted As Boolean
Dim objOL As Outlook.Application
Dim oItem As Outlook.MailItem
Dim objNS As NameSpace
outlookForceStarted = False

On Error Resume Next

'see if Outlook is running
errMsg = "Error checking if Microsoft Outlook is running." & vbCrLf & vbCrLf & "A failure at this point can indicate a problem with your Microsoft Outlook installation of a missing VBA reference to the Outlook Object Library."
Set objOL = GetObject(, "Outlook.Application")
If Err <> 0 Then
    'Outlook wasn't running, so start it
    errMsg = "Error starting Microsoft Outlook."
    Set objOL = CreateObject("Outlook.Application")
    objOL.Session.Logon
    outlookForceStarted = True
End If
On Error GoTo mapiTestError

Set objNS = objOL.GetNamespace("MAPI")
Set objfolder = objNS.GetDefaultFolder(olFolderInbox)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011
Commented:
"as long as references point to the right Outlook version" 
- yes you are right on this. if this working for the rest of other pc and fails on this one computer, it is likely the outlook dll is corrupted. you might need to copy the dll from other pc with Outlook 2010 and re-register the dll on that one pc or choose repair on uninstall option in control panel or last ersort is to reinstall outlook itself (do a backup of course). 
- you can also do a double check on reference to Microsoft Outlook xx.x Object Library which is on the correct version of Outlook 2010.

- another thing that i can suggest is to comment the On Error Resume Next and  On Error GoTo mapiTestError and execute it to see if its really that only line that gives the error.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial