Form On Error handling - ms-access

I am trying to improve my error handling code.
Using Access (2007) VBA:
When an error occurs in the forms On Error handler the variable DataErr gives me the error code but I have no access to the Err object.
Access to the Err object allows me to parse the error description and give a detailed custom message (eg error code 3314 exactly which field is causing the error) to the user
How can I have access to the Err object from the form's OnError handler? Not only the error code
Note:
I can access the Err object from code attached to the "save" and "delete" buttons on my form and give customised messages for duplicate keys, missing required fields, linked reecords that can not be deleted,etc.
This works fine if the user clicks these button. But if the user decides to select the next or previous row - which causes a save to occur - my code is not called and the user gets shown the standard MS Access error message

"if the user decides to select the next or previous row - which causes a save to occur - my code is not called and the user gets shown the standard MS Access error message"
Use the form's Before Update and Before Insert events to validate the current values. If any are unacceptable, you can assign True to the procedure's Cancel parameter, and notify the user about invalid values.

Related

Solution for ms access invalid IDA error 7879

I've made an Access database with a connection to a DWH table. A form with 3 drop-down boxes is made for the user to select the correct value. But the first time a drop-down value is selected the user receives an error (in Dutch). 'An invalid IDA has been passed to Microsoft Access error handling. Please report this error and the steps that caused it.'
After clicking 'Ok' the error doesn't show up when selecting a value form the second drop-down box (and the third) in the same form. Only when the user selects this form again the error pops up when selecting the first drop-down value.
The only VBA code linked to this form is:
Option Compare Database
Private Sub Form_Load()
Me.AantalVanCONTRACT_NUMBER.ColumnWidth = 1.556 * 1440
End Sub
The strange thing is that the form works fine because the selected value gets inputted in the DWH table, but getting this error every time is pretty annoying.

How can I fix the Error handler for my Macro in MS Access

I have a form that has buttons that view a record based on where [ID]=[Contact Name].
However, when the rows are blank, and the button is clicked I receive the error
Syntax error(missing operater)in query expression [id]
I am currently using the on click macro which opens the form to the condition:
="[ID]=" & [Contact Name]
I have attempted the on error method, however it still shows the standard MS Access error warning (Syntax error(missing operater)in query expression [id]) before showing mine which is "no contact in field"enter image description here

How to Change Table Validation Error Message in MS Access

I've got a set of fairly complicated table validation rules that I'm using to keep my data clean in one of my MS Access tables. The rules appear to be working well, but when a rule is violated it generates a nasty-looking error message. The whole string of rules comes up in the message - not exactly user-friendly.
I've tried to replace the message using code similar to this in the form's OnError event:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 2601 Then
MsgBox ("Case Number already entered")
Response = 0
End If
End Sub
However, apparently I haven't managed to find the correct error number because the If statement never fires. I checked here, but apparently it's not 3317 or 4001.
Also, when I removed the If statement and just had the MsgBox fire on any error, the standard error came up along with the message box - it's not being replaced.
Any idea how to address these issues?

How to check if an empty record is clicked in an Access subform?

I have a subform embedded in a main form. I have the following code for the onClick event of one field in my subform.
Private Sub my_field_Click()
If Not Me!my_field.Value Is Null Then
'my code here...
End If
End Sub
I want to update a text box with a click on the field, but I got an error when I click the field before the subform is not fully initiated (by setting the field's data source). So I wrote the above code to check if there is any value now in the field. However, I got the run-time error 424: Object required when running this code. Strangely, when I inspect the value of Me!my_field.Value in the debug window at run time, it does give NULL value.
Any idea what went wrong here? What else should I do to do this checking?
I am running this in Access 2000.
Use the IsNull() function in VBA code.
If Not IsNull(Me!my_field.Value) Then

Error during Closing the MS Access application

When i am closing the MS access application (application.mde) i am getting a error and looks like database has been refreshed and gettting a some other records.
Error Messaage : The Expression on unload you entered as the event property setting produced error:datatype mismatch in criteria expression.
Kindly help me on it.
the OnFormat property of the form /controls might be set to something other than the string "[Event Procedure]", or may not be named as a valid macro.