Link to home
Start Free TrialLog in
Avatar of John Clingeleffer
John ClingelefferFlag for Australia

asked on

Error Wih GetNameSpace

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)
ASKER CERTIFIED SOLUTION
Avatar of OP_Zaharin
OP_Zaharin
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial