Error trapping

isxaa1

Registered User.
Local time
Today, 23:15
Joined
Feb 26, 2003
Messages
11
I have a form with four input boxes, all of which are required and two
buttons, "OK" and "Cancel", for storing information in a table and closing
the form respectively. I have managed to get my error trapping code to work
for the above 2 buttons, but when I try to close the form from the "X"
button at the right top hand corner of the form, it gives me some errors
which I would like to have control by doing some error trapping. Can anyone
help me with this?

P.S: I tried the 'On Unload' and 'On Close' events but it doesn't work. The
weird thing is that i put a code to get the error number (Err.Number) and
although when i close the form from the 'X' it gives me an error, my extra
code shows me that the error number is 0. I am using Access 2000. Could
anyone help me as it is the fourth day and I am stuck.
 
The first error disappears but the second error still comes up. Here is my code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo ERRCONTROL

Cancel = True

Exit_This_Sub:
Exit Sub

ERRCONTROL:

MsgBox "Error: " & Err.Number
Resume Exit_This_Sub

End Sub

Can you please tell me what is going wrong?
Thank you for your previous reply
 
I have tried it but again it doen't work. I will give you all the details below:

'In the class module
Option Compare Database
Option Explicit
Dim gPendingError

'On Current
Private Sub Form_Current()
gPendingError = False
End Sub

'BeforeUpdate
Private Sub Form_BeforeUpdate(Cancel As Integer)
gPendingError = False

On Error GoTo ERRCONTROL

Cancel = True
gPendingError = True

Exit_This_Sub:

Exit Sub

ERRCONTROL:

MsgBox "Error: " & Err.Number

Resume Exit_This_Sub

End Sub

'On Unload
Private Sub Form_Unload(Cancel As Integer)
If gPendingError = True Then
MsgBox "You must fix the error before closing the form", vbOKOnly
Cancel = True
End If

End Sub


Please tell me what is the problem because it is driving me crazy!
 
Just in case that I didn't clarify my intentions. What I would like is that instead of having the standard Access errors being displayed, to have the errors but with my words that the end user will understand, as my system will be deployed in a company.
 
Could you please tell me explicitly what do you mean, as I am a novice in Access. Can you please make the corrections on the code that I have supplied. I would be very greatfull as I really truggle with this one. Thanks
 

Users who are viewing this thread

Back
Top Bottom