what is error trapping?

cyberz

New member
Local time
Today, 07:11
Joined
Sep 10, 2002
Messages
7
hi

i'm rebuilding an old db and want to include error trapping. however, i don't really know where to start.

does anyone know a quick guide or give a few examples?

cheers

cyberz
 
Correct me if I'm wrong.........

Error trapping is processes that the developer put in place to handle errors. Sounds really obvious when you put it like that.

Basically, you test the system as a really stupid user, put the wrong data types in fields, enter values that 'outside' of the range that it should be.

The idea of doing this is make tha database 'crash'. whenever it crashes, you put put in Error Trapping procedures that will pop a message rather than chrash the db.

eg Say the user entered a number of 666, but the maximun acceptable range is 600, the db may crash out. What you would do here is run the submitted string through some code to check that it less than 601, if it isn't then you would send a message to the user telling them that the data entered is outside of acceptable paramaters. if it is then submut the data to the database.

hope this helps
 
cool, thanks - i see i've got a lot of work to do!

so what are these On Err Goto...etc statements?

how do they work?

Martin
 
There's loads of different paramater settings for them your best bet is to check the help files.

hth
 
Here is an example of a simple Delete button with error trapping. Once you get the hang of using error traps,
you will then need to know what to do with expected errors such as my example does below...

Code:
Private Sub bDelete_Click()
On Error GoTo Err_bDelete_Click

    Beep
    If MsgBox("Are you sure you want to delete the current record?", vbQuestion + vbYesNo, "Delete Current Record?") = vbYes Then
        DoCmd.RunCommand acCmdDeleteRecord
    End If

Exit_bDelete_Click:
    Exit Sub

Err_bDelete_Click:
    If Err = 2501 Then 'The RunCommand action was canceled
        Exit Sub
    Else
        MsgBox Err.Number & " " & Err.Description
        Resume Exit_bDelete_Click
    End If
    
End Sub

This simple example does not check for a specific error code.

Code:
Private Sub bButton_Click()
On Error GoTo Err_bButton_Click

'Your code here

Exit_bButton_Click:
    Exit Sub

Err_bButton_Click:
    MsgBox Err.Number & " " & Err.Description
    Resume Exit_bButton_Click
    
End Sub

HTH
 

Users who are viewing this thread

Back
Top Bottom