I have a form over a table. The table has a number of fields that are required, i.e. cannot be null. I want to log any failures, by trapping the Form_Error event. But I can’t figure out *which* field out of 20 or so were left null. I’ve tried using AccessError, but it doesn’t tell me the field name. I can’t test the fields in the form, as they are previous (before update) values.
Any ideas?
Private Sub Form_Error(DataErr As Integer, Response As Integer) 'DataErr is the ADO (Jet Engine) error number. This is different 'to the Err object 'and Err.Description, which is for Visual Basic errors. 'The text for the DataErr error can be obtained via AccessError(DataErr) 'Some common errors are: '2113 Invalid field entry '2169 Record can't be saved at this time '3022 Duplicate key (index already exists) '3200 Can't delete because of a related record '3314 Field cannot contain Null If DataErr = 3314 Then 'Some field was left empty. Let's find out which one. 'Could be: Status, Officer Dim sFieldName As String sFieldName = "(unknown)" If IsNull(Me!cboStatus) Then sFieldName = "Status" If IsNull(Me!cmbOfficer) Then sFieldName = "Officer" 'The above tests don't work - it picks up the old values in the 'fields, not the changed or possibly made null values 'AccessError(DataErr) reports "The field '|' cannot contain null ... 'How do I decrypt the field name from that? 'Or where else can I obtain the field name? LogEvent "E24", "Field " & sFieldName & " cannot be null", _ "For Item Number [" & Me!ItemNumber & "]" 'Leave Response as is - access will display its own message box End If End Sub
Edited to eliminate horizontal scrolling–Charlotte