Avatar of John Clingeleffer
John Clingeleffer
Flag 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?


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")
    outlookForceStarted = True
End If
On Error GoTo mapiTestError

Set objNS = objOL.GetNamespace("MAPI")
Set objfolder = objNS.GetDefaultFolder(olFolderInbox)
Visual Basic ClassicMicrosoft Access

Avatar of undefined
Last Comment

8/22/2022 - Mon