Hi,
I have a bit of a problem with some code i have taken over from another developer.
I have an Access application that intergrates with outlook. I have copied the application to a new PC and it is failing when i initialize the outlook folders.
Can someone help as I have no idea why it is going wrong and i have not used these outlook modules before.
First of all I have a folder structure in outlook:
Public Folders
All Public Folders
Central
Archive
zFiling
A
B
etc....
And i am assuming my initialization is opening the folders.
I get 3 parameter values from a form
strOlFolder1 = Public Folders
strOlFolder2 = All Public Folders
strOlFolder3 = Central
the error i am getting is
3 - Error 1 -2147221233 The operation failed. An object could not be found.
3 - Error 1 424 Object required
This is happening from the OpenFolder function which calls the GetFolder function. It then fails on the:
Set GetFolder = GetFolder.Folders(strOlFolder3) - This is where it errors and i dont understand what it is trying to do or where to look.
Any help is really appreciated
Thanks
Private Sub Class_Initialize()
Dim olFolder As Outlook.MAPIFolder
Dim i As Long
Dim j As Long
Dim OlFolders As Outlook.Folders
On Error GoTo Handle
Set modOApOutlook = New Outlook.Application
Set modONsNamespace = modOApOutlook.GetNamespace("MAPI")
modONsNamespace.Logon sysOptions.Value("OutlookProfile"), sysOptions.Value("OutlookPassword"), False, True
Debug.Print "1 - 1 OpenFolder *Filing before opening folder Filing"
OpenFolder "*Filing" 'LOG: FAILING HERE
Debug.Print "1 - 2 after opeing folder Filing"
Public Sub OpenFolder(strMailbox As String, Optional strFolder As String = "")
Debug.Print "2 - 1 In OpenFolder Begining"
Debug.Print "2 - 2 before GetFolder"
Set modOlFCurrent = GetFolder(strMailbox, strFolder) 'LOG: FAILING HERE
Debug.Print "2 - 3 after GetFolder 'LOG: DOESNT GET THIS FAR"
modStrCurrMailbox = strMailbox
modStrCurrFolder = strFolder
End Sub
Private Function GetFolder(strOlFolder1 As String, Optional strOlFolder2 As String = "", _
Optional strOlFolder3 As String = "") As Outlook.MAPIFolder
Debug.Print "3 - 1 in GetFolder strOlFolder1,2,3 = " & strOlFolder1 & strOlFolder2 & strOlFolder3
On Error GoTo Handle
If strOlFolder1 = "*Archive" Then
Debug.Print "3 - 2 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & strOlFolder2 & strOlFolder3
Set GetFolder = GetFolder(CStr(sysOptions.Value("OutlookArchiveFolder1")), _
CStr(sysOptions.Value("OutlookArchiveFolder2")), _
CStr(sysOptions.Value("OutlookArchiveFolder3")))
ElseIf strOlFolder1 = "*Filing" Then
Debug.Print "3 - 3 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & strOlFolder2 & strOlFolder3
If CStr(sysOptions.Value("OutlookArchiveFolder3")) = "" Then
Set GetFolder = GetFolder(CStr(sysOptions.Value("OutlookArchiveFolder1")), _
"ZFiling", "")
Else
Debug.Print "3 - 4 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & " " & strOlFolder2 & " " & strOlFolder3
Set GetFolder = GetFolder(CStr(sysOptions.Value("OutlookArchiveFolder1")), _
CStr(sysOptions.Value("OutlookArchiveFolder2")), _
"ZFiling")
Debug.Print "3 - 5 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & strOlFolder2 & strOlFolder3
End If
Else
Debug.Print "3 - 6 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & " " & strOlFolder2 & " " & strOlFolder3
'Set GetFolder = modONsNamespace.Folders(strOlFolder1) 'AMENDED
Set GetFolder = modONsNamespace.Folders(strOlFolder1)
Debug.Print "3 - 7 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & " " & strOlFolder2 & " " & strOlFolder3
End If
If strOlFolder2 <> "" Then
Debug.Print "3 - 8 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & " " & strOlFolder2 & " " & strOlFolder3
Set GetFolder = GetFolder.Folders(strOlFolder2)
Debug.Print "3 - 9 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & " " & strOlFolder2 & " " & strOlFolder3
If strOlFolder3 <> "" Then
Debug.Print "3 - 10 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & " " & strOlFolder2 & " " & strOlFolder3
Set GetFolder = GetFolder.Folders(strOlFolder3) 'AMENDED
Debug.Print "3 - 11 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & " " & strOlFolder2 & " " & strOlFolder3
End If
Debug.Print "3 - 12 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & " " & strOlFolder2 & " " & strOlFolder3
End If
Finish:
Exit Function
Handle:
Debug.Print "3 - Error 1 " & Err.Number & " " & Err.Description
Set GetFolder = Null
Debug.Print "3 - Error 2 " & Err.Number & " " & Err.Description
MsgBox "Failed to open requested folder:" & vbCrLf & Err.Description
Debug.Print "3 - Error 4 " & Err.Number & " " & Err.Description
Resume Finish
End Function
I have a bit of a problem with some code i have taken over from another developer.
I have an Access application that intergrates with outlook. I have copied the application to a new PC and it is failing when i initialize the outlook folders.
Can someone help as I have no idea why it is going wrong and i have not used these outlook modules before.
First of all I have a folder structure in outlook:
Public Folders
All Public Folders
Central
Archive
zFiling
A
B
etc....
And i am assuming my initialization is opening the folders.
I get 3 parameter values from a form
strOlFolder1 = Public Folders
strOlFolder2 = All Public Folders
strOlFolder3 = Central
the error i am getting is
3 - Error 1 -2147221233 The operation failed. An object could not be found.
3 - Error 1 424 Object required
This is happening from the OpenFolder function which calls the GetFolder function. It then fails on the:
Set GetFolder = GetFolder.Folders(strOlFolder3) - This is where it errors and i dont understand what it is trying to do or where to look.
Any help is really appreciated
Thanks
Private Sub Class_Initialize()
Dim olFolder As Outlook.MAPIFolder
Dim i As Long
Dim j As Long
Dim OlFolders As Outlook.Folders
On Error GoTo Handle
Set modOApOutlook = New Outlook.Application
Set modONsNamespace = modOApOutlook.GetNamespace("MAPI")
modONsNamespace.Logon sysOptions.Value("OutlookProfile"), sysOptions.Value("OutlookPassword"), False, True
Debug.Print "1 - 1 OpenFolder *Filing before opening folder Filing"
OpenFolder "*Filing" 'LOG: FAILING HERE
Debug.Print "1 - 2 after opeing folder Filing"
Public Sub OpenFolder(strMailbox As String, Optional strFolder As String = "")
Debug.Print "2 - 1 In OpenFolder Begining"
Debug.Print "2 - 2 before GetFolder"
Set modOlFCurrent = GetFolder(strMailbox, strFolder) 'LOG: FAILING HERE
Debug.Print "2 - 3 after GetFolder 'LOG: DOESNT GET THIS FAR"
modStrCurrMailbox = strMailbox
modStrCurrFolder = strFolder
End Sub
Private Function GetFolder(strOlFolder1 As String, Optional strOlFolder2 As String = "", _
Optional strOlFolder3 As String = "") As Outlook.MAPIFolder
Debug.Print "3 - 1 in GetFolder strOlFolder1,2,3 = " & strOlFolder1 & strOlFolder2 & strOlFolder3
On Error GoTo Handle
If strOlFolder1 = "*Archive" Then
Debug.Print "3 - 2 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & strOlFolder2 & strOlFolder3
Set GetFolder = GetFolder(CStr(sysOptions.Value("OutlookArchiveFolder1")), _
CStr(sysOptions.Value("OutlookArchiveFolder2")), _
CStr(sysOptions.Value("OutlookArchiveFolder3")))
ElseIf strOlFolder1 = "*Filing" Then
Debug.Print "3 - 3 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & strOlFolder2 & strOlFolder3
If CStr(sysOptions.Value("OutlookArchiveFolder3")) = "" Then
Set GetFolder = GetFolder(CStr(sysOptions.Value("OutlookArchiveFolder1")), _
"ZFiling", "")
Else
Debug.Print "3 - 4 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & " " & strOlFolder2 & " " & strOlFolder3
Set GetFolder = GetFolder(CStr(sysOptions.Value("OutlookArchiveFolder1")), _
CStr(sysOptions.Value("OutlookArchiveFolder2")), _
"ZFiling")
Debug.Print "3 - 5 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & strOlFolder2 & strOlFolder3
End If
Else
Debug.Print "3 - 6 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & " " & strOlFolder2 & " " & strOlFolder3
'Set GetFolder = modONsNamespace.Folders(strOlFolder1) 'AMENDED
Set GetFolder = modONsNamespace.Folders(strOlFolder1)
Debug.Print "3 - 7 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & " " & strOlFolder2 & " " & strOlFolder3
End If
If strOlFolder2 <> "" Then
Debug.Print "3 - 8 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & " " & strOlFolder2 & " " & strOlFolder3
Set GetFolder = GetFolder.Folders(strOlFolder2)
Debug.Print "3 - 9 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & " " & strOlFolder2 & " " & strOlFolder3
If strOlFolder3 <> "" Then
Debug.Print "3 - 10 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & " " & strOlFolder2 & " " & strOlFolder3
Set GetFolder = GetFolder.Folders(strOlFolder3) 'AMENDED
Debug.Print "3 - 11 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & " " & strOlFolder2 & " " & strOlFolder3
End If
Debug.Print "3 - 12 in GetFolder strOlFolder1,2,3 =" & strOlFolder1 & " " & strOlFolder2 & " " & strOlFolder3
End If
Finish:
Exit Function
Handle:
Debug.Print "3 - Error 1 " & Err.Number & " " & Err.Description
Set GetFolder = Null
Debug.Print "3 - Error 2 " & Err.Number & " " & Err.Description
MsgBox "Failed to open requested folder:" & vbCrLf & Err.Description
Debug.Print "3 - Error 4 " & Err.Number & " " & Err.Description
Resume Finish
End Function