Best Approach on missing data Message Intercept

justphilip2003

Registered User.
Local time
Yesterday, 22:49
Joined
Mar 3, 2013
Messages
30
I have several fields that require data entry, combo boxes and simple text boxes. When I skip one of the require fields and depress my enter command button, an error message box appears with a message similar to (Run Time Error 3314 you must enter value in the ‘MainTbl.MainPur’ field). I believe on-error logic in the CmdEnter button Event is needed.
My problem is how to intercept these message an capture the field name in it so that I can post my own message in my “scrMessages’ field (ie. Trap error, Redirect program Flow to my error handler and end VBA error message by redirecting program flow to the missing field). TIA JP
 
Hi

It would not work error handling specifically, it would not know which field has not been missed.

The simple answer is data checking. So in the On_Click event of the Enter button, check each of the required fields for null values, and use message boxes to inform the user of the missing data.
Code:
If Nz(Me.Field1, "") = "" Then
    MsgBox "Field1 description has not been supplied", vbInformation, ""
    Exit Sub
End If

If Nz(Me.Field2, "") = "" Then
    MsgBox "Field2 description has not been supplied", vbInformation, ""
    Exit Sub
End If

If the user has missed more than 1 field, this will prompt them each time they press Enter.
The other way is to build a string variable with the field descriptions and display the whole list.
Code:
Dim strMsg As String

strMsg = ""

If Nz(Me.Field1, "") = "" Then strMsg = strMsg & "Field1 description"

If Nz(Me.Field2, "") = "" Then strMsg = strMsg & ", Field2 description"

If Left(strMsg, 2) = ", " Then strMsg = Right(strMsg, Len(strMsg) - 2)

If strMsg <> "" Then
    MsgBox "Please provide dat for the following fields;" & vbLf & strMsg, vbInformation, "Missing requried fields"
    Exit Sub
Else
    'your code
End If
 
Would not something like:

Err_Data_Missing_OnEnter:
If Err.Number = 3314 Then
' Me.Requery
scrMessages = "Required data missing!" & Err.Description & Err.Source
Else
scrMessages = "Call the exterminator, there is a bug in the system!"
End If

work? Probably would need some kind of statement to invoke "End" for error routine?TIA JP
 
I solved my problem with the following code:

Private Sub CmdEnter_Click()
On Error GoTo Err_Data_Missing_OnEnter
DoCmd.RunCommand acCmdRecordsGoToNew
scrMessages = ""
Exit_CmdEnter_Click:
Exit Sub
Err_Data_Missing_OnEnter:
If Err.Number = 3314 Then
' Me.Requery
scrMessages = "Ops!" & Err.Description & Err.Source
Else
scrMessages = "Call the exterminator, there is a bug in the system!"
End If
End Sub

This code is more generic, it specifies the field that was missing. It could be improved by testing Err.Description for the field name and then substitute the appropriate label. Thanks for the help! JP :D
 
Last edited:

Users who are viewing this thread

Back
Top Bottom