Strange error numbers when running code

  • Thread starter Thread starter vfr_stinger
  • Start date Start date
V

vfr_stinger

Good afternoon all.

After 20 years since I didn't wrote a single line of code I have
started to write some VB code for Outlook.

Installed on 10 Pc without any problem (both Windows 2000 and Windows
XP with Office 2003 Sp2, Outlook build 11.6568.6568), on a single
Windows XP client the code returns all those error messages all
together:

Error description: Outlook cannot do this action on this type of
attachment.
(error description is the same for all the error numbers)

Error numbers displayed are the following:
-71286779
-1940897787
-1629470715
-1318043643
-1040171003
-763346939
-417316859
-105889787
-1975500795
-1871691771
-1767882747
-1664073723
-1560264699
-1456455675
-1352646651
-1248837627

I tried to google around and the only information that may be somehow
related to this problem are the following.
http://support.microsoft.com/kb/824393
http://support.microsoft.com/kb/818588
http://support.microsoft.com/kb/235031

Of course none of them seems like to apply to my problem.

Does anyone had a similar problem or (better) a solution for that?

Of course also any suggestion on how to enhance the code will be very
appreciated.

P.S.
I apologise for my poor english and my not elegant code.

Here you can find the code.
*********************************

Sub GetEmailAttachment(MyMail As MailItem)

'Calling error handler
On Error GoTo GetAttachments_err

'This is the path were files will be saved
Const CONST_filepath As String = "c:\Email Attachments\"

Dim objNameSpace As NameSpace
Dim objDestNameSpaces As NameSpace
Dim objInbox As MAPIFolder
Dim objDestFolder As MAPIFolder
Dim objItem As Object
Dim objAttach As Attachment
Dim Subject As String
Dim SbjText As String
Dim Filename As String
Dim strTimeStamp As String
Dim strSender As String
Dim strSubject As String
Dim i As Integer
Dim varResponse As VbMsgBoxResult

Set objNameSpace = GetNamespace("MAPI")
Set objDestNameSpace = GetNamespace("MAPI")
Set objInbox = objNameSpace.GetDefaultFolder(olFolderInbox) 'Set the
Inbox folder
Set objDestFolder =
objDestNameSpace.Folders("images_archive").Folders("Images_Archive")
'Set the subfolder in the archive
i = 0

'If there are unread messages (only e-mail, not calendar,
'appointments, etc..) in the Inbox folder
'the macro will proceed to examine each for attachments
'and will save them in a fixed path (declared in the constant)
'The SaveAsFile method used to save an attachment
'will overwrite an existing file of the same name without warning.
'in order to avoid any data overwrite the macro will append
'sender's name, the subject of the message and message's time stamp
'(dd.mm.yyyy_hh.nn.ss) before the file name,
'then it will flag *.tif and *.tiff files with a Blue flag,
'*.jpg and *.jpeg files with a Green flag.
'and *.pdf files with a Red flag.
'once finished all those operations messages will be moved
'in the subfolder of the *.pst file (see line 103).
For Each objItem In objInbox.Items
If objItem.Class = olMail And objItem.UnRead = True Then
For Each objAttach In objItem.Attachments
If Right(objAttach.Filename, 4) = ".tif" Then
strSubject = GetValidFileName(objItem.Subject)
strSender = GetValidFileName(objItem.SenderName)
strTimeStamp = Format(objItem.ReceivedTime, "dd.mm.yy-
hh.nn.ss")
Filename = CONST_filepath & strSender & " - " &
strSubject & " - " & strTimeStamp & " - " & objAttach.Filename
objAttach.SaveAsFile Filename
i = i + 1
objItem.FlagIcon = OlFlagIcon.olGreenFlagIcon
objItem.Save
End If
If Right(objAttach.Filename, 4) = "tiff" Then
strSubject = GetValidFileName(objItem.Subject)
strSender = GetValidFileName(objItem.SenderName)
strTimeStamp = Format(objItem.ReceivedTime, "dd.mm.yy-
hh.nn.ss")
Filename = CONST_filepath & strSender & " - " &
strSubject & " - " & strTimeStamp & " - " & objAttach.Filename
objAttach.SaveAsFile Filename
i = i + 1
objItem.FlagIcon = OlFlagIcon.olGreenFlagIcon
objItem.Save
End If
If Right(objAttach.Filename, 4) = ".jpg" Then
strSubject = GetValidFileName(objItem.Subject)
strSender = GetValidFileName(objItem.SenderName)
strTimeStamp = Format(objItem.ReceivedTime, "dd.mm.yy-
hh.nn.ss")
Filename = CONST_filepath & strSender & " - " &
strSubject & " - " & strTimeStamp & " - " & objAttach.Filename
objAttach.SaveAsFile Filename
i = i + 1
objItem.FlagIcon = OlFlagIcon.olBlueFlagIcon
objItem.Save
End If
If Right(objAttach.Filename, 4) = "jpeg" Then
strSubject = GetValidFileName(objItem.Subject)
strSender = GetValidFileName(objItem.SenderName)
strTimeStamp = Format(objItem.ReceivedTime, "dd.mm.yy-
hh.nn.ss")
Filename = CONST_filepath & strSender & " - " &
strSubject & " - " & strTimeStamp & " - " & objAttach.Filename
objAttach.SaveAsFile Filename
i = i + 1
objItem.FlagIcon = OlFlagIcon.olBlueFlagIcon
objItem.Save
End If
If Right(objAttach.Filename, 4) = ".pdf" Then
strSubject = GetValidFileName(objItem.Subject)
strSender = GetValidFileName(objItem.SenderName)
strTimeStamp = Format(objItem.ReceivedTime, "dd.mm.yy-
hh.nn.ss")
Filename = CONST_filepath & strSender & " - " &
strSubject & " - " & strTimeStamp & " - " & objAttach.Filename
objAttach.SaveAsFile Filename
i = i + 1
objItem.FlagIcon = OlFlagIcon.olRedFlagIcon
objItem.Save
End If
Next objAttach
'Moving the flagged messages to the Archive (*.pst file)
If objItem.FlagStatus = olFlagMarked Then
objItem.Move objDestFolder
End If
End If
Next

'Display a summary message
If i > 0 Then
varResponse = MsgBox("I found " & i & " attached files." _
& vbCrLf & "The original messages containing an image " _
& vbCrLf & "has been moved into Images Archive" _
& vbCrLf & "and a copy of the attachment has been saved " _
& vbCrLf & "into the " & CONST_filepath & " folder" _
& vbCrLf & "from where you can open it in the usual manner " _
& vbCrLf & vbCrLf & "Would you like to view it now?" _
, vbQuestion + vbYesNo + vbDefaultButton2, "Finished!")
If varResponse = vbYes Then
Shell "Explorer.exe /e," & CONST_filepath, vbNormalFocus
End If
End If

'Clear the memory
GetAttachments_exit:
Set objNameSpace = Nothing
Set objDestNameSpace = Nothing
Set objInbox = Nothing
Set objDestFolder = Nothing
Set objItem = Nothing
Set objAttach = Nothing
Exit Sub

Error handler
GetAttachments_err:
MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please contact Technical Support." _
& vbCrLf & "Macro Name: GetAttachments" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
Resume GetAttachments_exit

End Sub

'This function cleans the text extracted by the Subject and SenderName
fields
'from all those characters not allowed for a file name.

Function GetValidFileName(InputString) As String
GetValidFileName = Replace(InputString, ":", " ")
GetValidFileName = Replace(GetValidFileName, "/", " ")
GetValidFileName = Replace(GetValidFileName, "\", " ")
GetValidFileName = Replace(GetValidFileName, "*", " ")
GetValidFileName = Replace(GetValidFileName, "?", " ")
GetValidFileName = Replace(GetValidFileName, "<", " ")
GetValidFileName = Replace(GetValidFileName, ">", " ")
GetValidFileName = Replace(GetValidFileName, "|", " ")
GetValidFileName = Replace(GetValidFileName, """", " ")
End Function
 
Please make clear at which line in your code theerrorcomes up.

Good question! The problem is that debugging the code no error is
detected.

I forgot to mention that I run this code as a rule in Outlook and when
the rule runs it cames up with those errors on that single Pc.

I already tried to start from scratch recreating the *.pst file,
reloading the code and recreating the rule but nothing has changed.

The same code used as a macro runs perfectly onto 8 Windows 2000 and 4
Windows XP Pc's (that are supposed to have the same settings because
installed via Ghost) .

This thing is driving me crazy.

Maybe I should post this message on another group because the problem
is not related to the code?

Thanks for you attention.

Giangerolamo Pirinoli.
 
Unfortunately, it's usual that you get a lot of different numbers for maybe
the same error. So the error message would be more useful.

You could download mztools from http://www.mztools.com/index.htm, which is
for free for VB(A). With that you can insert line numbers easily.

Then edit your error handler to give you also the line number that causes
the error. The number is returned by the Erl function.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Quick-Cats - Categorize Outlook data:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am 3 May 2007 02:49:13 -0700 schrieb (e-mail address removed):
 
Unfortunately, it's usual that you get a lot of different numbers for maybe
the same error. So the error message would be more useful.

You could download mztools fromhttp://www.mztools.com/index.htm, which is
for free for VB(A). With that you can insert line numbers easily.

Then edit your error handler to give you also the line number that causes
the error. The number is returned by the Erl function.

Thank you very much Michael, mztool is really usefull.

By the way I found the problem.

For some unknown reasons and in a (apparently) random way (so, not
always), when a Meeting Request is received or an Unread one is
present in the Inbox folder the macro returns that error codes despite
the fact that:
If objItem.Class = olMail And objItem.UnRead = True Then

So I added a label before the code that gives the summary message and
an ElseIf string as follows

For Each objItem In objInbox.Items
If objItem.Class = olMail And objItem.UnRead = True Then

...yadda..yadda..yadda..

Next objAttach
'Moving the flagged messages to the Archive (*.pst file)
If objItem.FlagStatus = olFlagMarked Then
objItem.Move objDestFolder
End If
ElseIf objItem.Class = olMeetingRequest Then GoTo GetAttachments_popup
End If
Next

'Display a summary message
GetAttachments_popup:

....monkey proof popup for users...


Now, could be useful to know why VBA (or the collection?) sometimes
makes confusion between mail messages and Meeting Request. It should
be different items, isn't it?

Thanks in advance and regards.

Giangerolamo Pirinoli.
 
I'm quite sure, it's not VBA that confuses here :)

If the item is a MeetingItem then the Class property isn't olMail, but one
of the olMeeting* values.

Another source for errors is that you must not move an item out of a For
Each loop. Use a For Next loop instead that counts backwards.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Quick-Cats - Categorize Outlook data:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am 4 May 2007 05:42:32 -0700 schrieb (e-mail address removed):
 
I'm quite sure, it's not VBA that confuses here :)

Talking about VBA I know that I am the most confused person in the
world, remember that last time I wrote some code was 20 years ago and
the language was TurboPascal ;-)
Another source for errors is that you must not move an item out of a For
Each loop. Use a For Next loop instead that counts backwards.

That's interesting.

Of course I don't want you to write the code for me but I'd really
appreciate some examples on how can I modify my code.

Thanks in advance and regards.

Giangerolamo Pirinoli
 
Changed the code.

It works fantastically.

Thank you very much indeed!

Giangerolamo Pirinoli.
 
I am facing the same problem and let me know what changes u made in the code.

Thanks,



vfr_stinge wrote:

Changed the code.It works fantastically.Thank you very much indeed!
09-May-07

Changed the code.

It works fantastically.

Thank you very much indeed!

Giangerolamo Pirinoli.

wrote:

Previous Posts In This Thread:

Strange error numbers when running code
Good afternoon all.

After 20 years since I didn't wrote a single line of code I have
started to write some VB code for Outlook.

Installed on 10 Pc without any problem (both Windows 2000 and Windows
XP with Office 2003 Sp2, Outlook build 11.6568.6568), on a single
Windows XP client the code returns all those error messages all
together:

Error description: Outlook cannot do this action on this type of
attachment.
(error description is the same for all the error numbers)

Error numbers displayed are the following:
-71286779
-1940897787
-1629470715
-1318043643
-1040171003
-763346939
-417316859
-105889787
-1975500795
-1871691771
-1767882747
-1664073723
-1560264699
-1456455675
-1352646651
-1248837627

I tried to google around and the only information that may be somehow
related to this problem are the following.
http://support.microsoft.com/kb/824393
http://support.microsoft.com/kb/818588
http://support.microsoft.com/kb/235031

Of course none of them seems like to apply to my problem.

Does anyone had a similar problem or (better) a solution for that?

Of course also any suggestion on how to enhance the code will be very
appreciated.

P.S.
I apologise for my poor english and my not elegant code.

Here you can find the code.
*********************************

Sub GetEmailAttachment(MyMail As MailItem)

'Calling error handler
On Error GoTo GetAttachments_err

'This is the path were files will be saved
Const CONST_filepath As String = "c:\Email Attachments\"

Dim objNameSpace As NameSpace
Dim objDestNameSpaces As NameSpace
Dim objInbox As MAPIFolder
Dim objDestFolder As MAPIFolder
Dim objItem As Object
Dim objAttach As Attachment
Dim Subject As String
Dim SbjText As String
Dim Filename As String
Dim strTimeStamp As String
Dim strSender As String
Dim strSubject As String
Dim i As Integer
Dim varResponse As VbMsgBoxResult

Set objNameSpace = GetNamespace("MAPI")
Set objDestNameSpace = GetNamespace("MAPI")
Set objInbox = objNameSpace.GetDefaultFolder(olFolderInbox) 'Set the
Inbox folder
Set objDestFolder =
objDestNameSpace.Folders("images_archive").Folders("Images_Archive")
'Set the subfolder in the archive
i = 0

'If there are unread messages (only e-mail, not calendar,
'appointments, etc..) in the Inbox folder
'the macro will proceed to examine each for attachments
'and will save them in a fixed path (declared in the constant)
'The SaveAsFile method used to save an attachment
'will overwrite an existing file of the same name without warning.
'in order to avoid any data overwrite the macro will append
'sender's name, the subject of the message and message's time stamp
'(dd.mm.yyyy_hh.nn.ss) before the file name,
'then it will flag *.tif and *.tiff files with a Blue flag,
'*.jpg and *.jpeg files with a Green flag.
'and *.pdf files with a Red flag.
'once finished all those operations messages will be moved
'in the subfolder of the *.pst file (see line 103).
For Each objItem In objInbox.Items
If objItem.Class = olMail And objItem.UnRead = True Then
For Each objAttach In objItem.Attachments
If Right(objAttach.Filename, 4) = ".tif" Then
strSubject = GetValidFileName(objItem.Subject)
strSender = GetValidFileName(objItem.SenderName)
strTimeStamp = Format(objItem.ReceivedTime, "dd.mm.yy-
hh.nn.ss")
Filename = CONST_filepath & strSender & " - " &
strSubject & " - " & strTimeStamp & " - " & objAttach.Filename
objAttach.SaveAsFile Filename
i = i + 1
objItem.FlagIcon = OlFlagIcon.olGreenFlagIcon
objItem.Save
End If
If Right(objAttach.Filename, 4) = "tiff" Then
strSubject = GetValidFileName(objItem.Subject)
strSender = GetValidFileName(objItem.SenderName)
strTimeStamp = Format(objItem.ReceivedTime, "dd.mm.yy-
hh.nn.ss")
Filename = CONST_filepath & strSender & " - " &
strSubject & " - " & strTimeStamp & " - " & objAttach.Filename
objAttach.SaveAsFile Filename
i = i + 1
objItem.FlagIcon = OlFlagIcon.olGreenFlagIcon
objItem.Save
End If
If Right(objAttach.Filename, 4) = ".jpg" Then
strSubject = GetValidFileName(objItem.Subject)
strSender = GetValidFileName(objItem.SenderName)
strTimeStamp = Format(objItem.ReceivedTime, "dd.mm.yy-
hh.nn.ss")
Filename = CONST_filepath & strSender & " - " &
strSubject & " - " & strTimeStamp & " - " & objAttach.Filename
objAttach.SaveAsFile Filename
i = i + 1
objItem.FlagIcon = OlFlagIcon.olBlueFlagIcon
objItem.Save
End If
If Right(objAttach.Filename, 4) = "jpeg" Then
strSubject = GetValidFileName(objItem.Subject)
strSender = GetValidFileName(objItem.SenderName)
strTimeStamp = Format(objItem.ReceivedTime, "dd.mm.yy-
hh.nn.ss")
Filename = CONST_filepath & strSender & " - " &
strSubject & " - " & strTimeStamp & " - " & objAttach.Filename
objAttach.SaveAsFile Filename
i = i + 1
objItem.FlagIcon = OlFlagIcon.olBlueFlagIcon
objItem.Save
End If
If Right(objAttach.Filename, 4) = ".pdf" Then
strSubject = GetValidFileName(objItem.Subject)
strSender = GetValidFileName(objItem.SenderName)
strTimeStamp = Format(objItem.ReceivedTime, "dd.mm.yy-
hh.nn.ss")
Filename = CONST_filepath & strSender & " - " &
strSubject & " - " & strTimeStamp & " - " & objAttach.Filename
objAttach.SaveAsFile Filename
i = i + 1
objItem.FlagIcon = OlFlagIcon.olRedFlagIcon
objItem.Save
End If
Next objAttach
'Moving the flagged messages to the Archive (*.pst file)
If objItem.FlagStatus = olFlagMarked Then
objItem.Move objDestFolder
End If
End If
Next

'Display a summary message
If i > 0 Then
varResponse = MsgBox("I found " & i & " attached files." _
& vbCrLf & "The original messages containing an image " _
& vbCrLf & "has been moved into Images Archive" _
& vbCrLf & "and a copy of the attachment has been saved " _
& vbCrLf & "into the " & CONST_filepath & " folder" _
& vbCrLf & "from where you can open it in the usual manner " _
& vbCrLf & vbCrLf & "Would you like to view it now?" _
, vbQuestion + vbYesNo + vbDefaultButton2, "Finished!")
If varResponse = vbYes Then
Shell "Explorer.exe /e," & CONST_filepath, vbNormalFocus
End If
End If

'Clear the memory
GetAttachments_exit:
Set objNameSpace = Nothing
Set objDestNameSpace = Nothing
Set objInbox = Nothing
Set objDestFolder = Nothing
Set objItem = Nothing
Set objAttach = Nothing
Exit Sub

Error handler
GetAttachments_err:
MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please contact Technical Support." _
& vbCrLf & "Macro Name: GetAttachments" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
Resume GetAttachments_exit

End Sub

'This function cleans the text extracted by the Subject and SenderName
fields
'from all those characters not allowed for a file name.

Function GetValidFileName(InputString) As String
GetValidFileName = Replace(InputString, ":", " ")
GetValidFileName = Replace(GetValidFileName, "/", " ")
GetValidFileName = Replace(GetValidFileName, "\", " ")
GetValidFileName = Replace(GetValidFileName, "*", " ")
GetValidFileName = Replace(GetValidFileName, "?", " ")
GetValidFileName = Replace(GetValidFileName, "<", " ")
GetValidFileName = Replace(GetValidFileName, ">", " ")
GetValidFileName = Replace(GetValidFileName, "|", " ")
GetValidFileName = Replace(GetValidFileName, """", " ")
End Function

Please make clear at which line in your code the error comes up.
Please make clear at which line in your code the error comes up.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Quick-Cats - Categorize Outlook data:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am 2 May 2007 07:47:09 -0700 schrieb (e-mail address removed):

Re: Strange error numbers when running code
On 3 May, 06:16, "Michael Bauer [MVP - Outlook]" <[email protected]>
wrote:

Good question! The problem is that debugging the code no error is
detected.

I forgot to mention that I run this code as a rule in Outlook and when
the rule runs it cames up with those errors on that single Pc.

I already tried to start from scratch recreating the *.pst file,
reloading the code and recreating the rule but nothing has changed.

The same code used as a macro runs perfectly onto 8 Windows 2000 and 4
Windows XP Pc's (that are supposed to have the same settings because
installed via Ghost) .

This thing is driving me crazy.

Maybe I should post this message on another group because the problem
is not related to the code?

Thanks for you attention.

Giangerolamo Pirinoli.

Unfortunately, it's usual that you get a lot of different numbers for maybethe
Unfortunately, it's usual that you get a lot of different numbers for maybe
the same error. So the error message would be more useful.

You could download mztools from http://www.mztools.com/index.htm, which is
for free for VB(A). With that you can insert line numbers easily.

Then edit your error handler to give you also the line number that causes
the error. The number is returned by the Erl function.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Quick-Cats - Categorize Outlook data:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am 3 May 2007 02:49:13 -0700 schrieb (e-mail address removed):

Re: Strange error numbers when running code
On May 4, 6:21 am, "Michael Bauer [MVP - Outlook]" <[email protected]>
wrote:

Thank you very much Michael, mztool is really usefull.

By the way I found the problem.

For some unknown reasons and in a (apparently) random way (so, not
always), when a Meeting Request is received or an Unread one is
present in the Inbox folder the macro returns that error codes despite
the fact that:
If objItem.Class = olMail And objItem.UnRead = True Then

So I added a label before the code that gives the summary message and
an ElseIf string as follows

For Each objItem In objInbox.Items
If objItem.Class = olMail And objItem.UnRead = True Then

...yadda..yadda..yadda..

Next objAttach
'Moving the flagged messages to the Archive (*.pst file)
If objItem.FlagStatus = olFlagMarked Then
objItem.Move objDestFolder
End If
End If
Next

'Display a summary message

....monkey proof popup for users...


Now, could be useful to know why VBA (or the collection?) sometimes
makes confusion between mail messages and Meeting Request. It should
be different items, isn't it?

Thanks in advance and regards.

Giangerolamo Pirinoli.

Re: Strange error numbers when running code
I'm quite sure, it's not VBA that confuses here :)

If the item is a MeetingItem then the Class property isn't olMail, but one
of the olMeeting* values.

Another source for errors is that you must not move an item out of a For
Each loop. Use a For Next loop instead that counts backwards.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Quick-Cats - Categorize Outlook data:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am 4 May 2007 05:42:32 -0700 schrieb (e-mail address removed):

maybe

Re: Strange error numbers when running code
On May 5, 8:12 am, "Michael Bauer [MVP - Outlook]" <[email protected]>
wrote:

Talking about VBA I know that I am the most confused person in the
world, remember that last time I wrote some code was 20 years ago and
the language was TurboPascal ;-)


That's interesting.

Of course I don't want you to write the code for me but I'd really
appreciate some examples on how can I modify my code.

Thanks in advance and regards.

Giangerolamo Pirinoli

Re: Strange error numbers when running code
This is a sample for the backwards loop:

Dim i&
Dim Items as outlook.Items

Set Items=objInbox.Items
For i=Items.Count to 1 step-1
Set objItem=Items(i)
...
Next

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Quick-Cats - Categorize Outlook data:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am 8 May 2007 01:52:46 -0700 schrieb (e-mail address removed):

Changed the code.It works fantastically.Thank you very much indeed!
Changed the code.

It works fantastically.

Thank you very much indeed!

Giangerolamo Pirinoli.

wrote:

EggHeadCafe - Software Developer Portal of Choice
Speed Up Sql Server Data Inserts With SqlBulkCopy
http://www.eggheadcafe.com/tutorial...18-cee8a2357251/speed-up-sql-server-data.aspx
 
Back
Top