View Full Version : Error handling not execued second time


jason_nevin
11-10-2006, 09:01 AM
I have some cde in which I'm trying to ignore error 3349 whenever it occurs. The code ignores it fine the first time but the second time the error occurs the code does not seen to go into the error handler. Can anyone help?

Private Sub butGo_Click()
Dim db As DAO.database
Dim tdf As DAO.tabledef
Dim rst As DAO.Recordset
Dim f As Integer
Dim SearchString As String
Dim TableName As String
Dim FieldName As String
Dim LookupString As String
Dim RowNo As Integer


On Error GoTo HandleErrors

SearchString = "Pearce"

Set db = CurrentDb()

' get the names of all tables in the database
For Each tdf In db.TableDefs

' ignore system tables
If Left$(tdf.Name, 4) = "MSys" Then
GoTo Next_Rec
End If

TableName = tdf.Name
Debug.Print "Searching table " & TableName

Set rst = db.OpenRecordset(TableName)

RowNo = 1

With rst
Do Until .EOF
.MoveNext
RowNo = RowNo + 1
Debug.Print RowNo

' loop each column in the table
For f = 0 To rst.Fields.Count - 1

' only search general fields (not numeric)
If .Fields(f).Type = 10 Then

FieldName = .Fields(f).Name

If Not IsNumeric(.Fields(f).Value) And _
Not IsNull(.Fields(f).Value) Then
If InStr(.Fields(f).Value, SearchString) > 0 Then
' Debug.Print RowNo
End If

End If
ResumeHere:
End If

Next

Loop

.Close

Set rst = Nothing

End With

Next_Rec:
Next tdf

Set db = Nothing
Set tdf = Nothing

ExitHere:
Exit Sub

HandleErrors:
Select Case Err.Number
Case 3349
Err.Clear
GoTo ResumeHere
Case Else
MsgBox "Error: " & Err.Description & _
" (" & Err.Number & ")"
End Select
Resume ExitHere

End Sub

Bodisathva
11-10-2006, 10:52 AM
try this modification to your error handler:

HandleErrors:
Select Case Err.Number
Case 3349
Resume Next 'If you really need to go back to the ResumeHere position,
you would, obviously, replace Next with ResumeHere
Case Else
MsgBox "Error: " & Err.Description & _
" (" & Err.Number & ")"
Resume ExitHere
End Select

gemma-the-husky
11-10-2006, 05:50 PM
i think you will notice thst when you resume after the first error, you do not reset the error handler, because that is OUTSIDE the loop. put the error handler within the loop, and it will reset.