Ainaken
March 15th, 2001, 10:57 AM
I have a error handler in a "FOR,NEXT" loop, it do opens a file system object and writes the error into a log file.The issue is I did't set the "EXIt sub" but i specified the handler to go to the "next" statement because i dont want the error handler to exit sub. it does go to the for loop again runs the loop,if i have an error again the handler FAILS...
Guys if u got anything Please reply me back, Any help will be greatly appreciated
"Ainaken SARAN PARAMATMUNI"
The Code Follows :
Private Sub Command2_Click()
MAPISession1.SignOn
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Fetch
For i = 0 To MAPIMessages1.MsgCount - 1
On Error GoTo logerr
MAPIMessages1.MsgIndex = i
If Not MAPIMessages1.MsgRead = True Then
If Not Len(MAPIMessages1.MsgSubject) = 0 Then
strSubject = MAPIMessages1.MsgSubject
Else
strSubject = MAPIMessages1.MsgOrigDisplayName
End If
If Not Len(MAPIMessages1.MsgNoteText) = 0 Then
strNoteTxt = MAPIMessages1.MsgNoteText
End If
If Not Len(MAPIMessages1.MsgOrigDisplayName) = 0 Then
strFromAdd = MAPIMessages1.MsgOrigDisplayName
End If
Set file = fso.CreateTextFile("C:\Documents and Settings\MythelS1\Desktop\EmailSource\" & strSubject & ".txt", True)
file.Close
Set Getfile = fso.Getfile("C:\Documents and Settings\MythelS1\Desktop\EmailSource\" & strSubject & ".txt")
Set writefile = Getfile.OpenAsTextStream(ForWriting)
With writefile
.Write strNoteTxt
.Close
End With
Command2.Enabled = True
End If
Command2.Enabled = False
MAPISession1.NewSession = True
99: Next
MAPISession1.SignOff
'----ERROR HANDLER-----
logerr:
If Not Err = 0 Then
logerror = Err.Description & vbNewLine & _
"Error" & Err.Description & " occurred in writing down the textfile" & vbNewLine & _
strFromAdd & vbNewLine & vbNewLine & strSubject & vbNewLine & Now
Set Logfile = fso.OpenTextFile("C:\Documents and Settings\MythelS1\Desktop\log.txt", ForWriting)
With Logfile
.Write logerror
.Close
End With
Err.Clear
GoTo 99
End If
End Sub
Guys if u got anything Please reply me back, Any help will be greatly appreciated
"Ainaken SARAN PARAMATMUNI"
The Code Follows :
Private Sub Command2_Click()
MAPISession1.SignOn
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Fetch
For i = 0 To MAPIMessages1.MsgCount - 1
On Error GoTo logerr
MAPIMessages1.MsgIndex = i
If Not MAPIMessages1.MsgRead = True Then
If Not Len(MAPIMessages1.MsgSubject) = 0 Then
strSubject = MAPIMessages1.MsgSubject
Else
strSubject = MAPIMessages1.MsgOrigDisplayName
End If
If Not Len(MAPIMessages1.MsgNoteText) = 0 Then
strNoteTxt = MAPIMessages1.MsgNoteText
End If
If Not Len(MAPIMessages1.MsgOrigDisplayName) = 0 Then
strFromAdd = MAPIMessages1.MsgOrigDisplayName
End If
Set file = fso.CreateTextFile("C:\Documents and Settings\MythelS1\Desktop\EmailSource\" & strSubject & ".txt", True)
file.Close
Set Getfile = fso.Getfile("C:\Documents and Settings\MythelS1\Desktop\EmailSource\" & strSubject & ".txt")
Set writefile = Getfile.OpenAsTextStream(ForWriting)
With writefile
.Write strNoteTxt
.Close
End With
Command2.Enabled = True
End If
Command2.Enabled = False
MAPISession1.NewSession = True
99: Next
MAPISession1.SignOff
'----ERROR HANDLER-----
logerr:
If Not Err = 0 Then
logerror = Err.Description & vbNewLine & _
"Error" & Err.Description & " occurred in writing down the textfile" & vbNewLine & _
strFromAdd & vbNewLine & vbNewLine & strSubject & vbNewLine & Now
Set Logfile = fso.OpenTextFile("C:\Documents and Settings\MythelS1\Desktop\log.txt", ForWriting)
With Logfile
.Write logerror
.Close
End With
Err.Clear
GoTo 99
End If
End Sub