in the below code i am forced to trap/resume err 13 or the code falls over when the loop hits the first (oldest) appointment request.
this seems inelegant: is there a better way?
TIA, izyrider
| Code: |
Public Sub cmCategorise()
On Error GoTo err_cmCategorise
Dim obMsg As Outlook.MailItem
Dim obNameSpace As NameSpace
Dim obInbox As Outlook.MAPIFolder
Dim i As Integer
Set obNameSpace = Application.GetNamespace("MAPI")
Set obInbox = obNameSpace.GetDefaultFolder(olFolderInbox)
'is it working - just count for the moment
For Each obMsg In obInbox.Items
i = i + 1
Next
MsgBox "There are " & i & " items in the inbox"
exit_cmCategorise:
On Error Resume Next
Set obInbox = Nothing
Set obNameSpace = Nothing
Exit Sub
err_cmCategorise:
Select Case Err.Number
Case 13
Resume
Case Else
MsgBox Err.Number & ": " & Err.Description, vbExclamation, "ERROR in cmCategorise"
Resume exit_cmCategorise
End Select
End Sub
|