Modify the Default Error Msg

  • Thread starter Thread starter TomP
  • Start date Start date
T

TomP

Background:
In my main table, I have a field that must be completed before they enter a
new record. I selected "Yes" under the General Tab labeled "Required".

Question:
In my form, I get a default message before I create a new record that says
"You can't go to the specified record." In my mind, I understand what the
message means, but I was wondering, how can I change the wording to say
something like "You must enter "....." before you continue. Click OK to
continue. "

I hope this makes sense... thank you for your help,

Tom
 
You trap it with code in the Error event of the form, but there's a much
simpler way. Use a Validation Rule instead of the Required property.

1. Open the table in design view.

2. Select the field.

3. Set its Required property to No.

4. Set its Validation Rule to:
Is Not Null

5. Set its Validation Text to whatever message you want.
 
The validation rule is being used already to limit certain response which
says "Enter only "SA", "NS", or "PA".

I couldn't find the Error event on the form. Is it under the "Event" tab?
If so, which event category should I select to create a message if the field
is blank?

Thank you for your help!
 
Yes: the form's Error event is on the Event tab of the Properties sheet,
when looking at the properties of the *form* (not of a text box.)

I still think it would be easier to use the Validation Rule:
IN ('SA', 'NS', 'PA') AND (Is Not Null)
Validation Text:
Choose "SA", "NS", or "PA". Cannot be blank.

Of course, a better solution would be to create a little lookup table of the
valid values.
 
The validation rule worked OK, but I'm still stuck with the default error msg
that says "You can't go to the specified record". How can I modify the error
message so I can give specific instructions on why the message appeared?

I found the Error Event as mention at the form's property though. This is
what I entered.

Private Sub Form_Error(DataErr As Integer, Response As Integer)
If Me.CASELOAD.Text = Not Null Then
MsgBox "A caseload type must be entered in order to continue.", vbCritical,
"CASELOAD Error Message"
Exit Sub
End If
End Sub

I still get the default "You can't go to the specified record".
 
You have to trap the actual error, 2105 in this case, not what you think is
causing it!

Private Sub Form_Error(DataErr As Integer, Response As Integer)
Dim Message As String
If DataErr = 2105 Then 'Can't go to specified record
Message = "Place your custom message here"
Response = MsgBox(Message, vbExclamation)
Response = acDataErrContinue
End If
End Sub
 
I tried the script as shown below and for some reason I get the same default
error message. I even tried the code as shown below to display the actual
error number and nothing happens.

Private Sub Form_Error(DataErr As Integer, Response As Integer)
Debug.Print "DataErr = "; DataErr
End Sub

Thank you for your help!
 
In Form_Error, include the MsgBox for the message you want.

Then set the Response argument to suppress the built-in message.
On-line help for the Error event (in the Code window) will give details.
 
The argument from the Form_Error works. But, I don't understand why it
doesn't work when I use the command button. I copied/paste the text from the
form_error and added to the Add New Record button and this is the error I get
"You can't go to the specirfied record."

Private Sub Command182_Click()

Const conErrRequiredData = 3314

If DataErr = conErrRequiredData Then
MsgBox "Please ensure that you enter a caseload type before you
continue!", vbCritical, "Caseload Type Error Message"
Response = acDataErrContinue
Else
'Display a standard error message
Response = acDataErrDisplay
End If

On Error GoTo Err_Command182_Click

DoCmd.GoToRecord , , acNewRec

Exit_Command182_Click:
Exit Sub

Err_Command182_Click:
MsgBox Err.Description
Resume Exit_Command182_Click

End Sub

Thank you for your help!

Tom
 
Tom,

this code has a syntax problem on the 2nd line

Private Sub Form_Error(DataErr As Integer, Response As Integer)
If Me.CASELOAD.Text = Not Null Then
MsgBox "A caseload type must be entered in order to continue.", vbCritical,
"CASELOAD Error Message"
Exit Sub
End If
End Sub

This line
If Me.CASELOAD.Text = Not Null Then

rewrite like this

If Not IsNull(Me.CASELOAD) Then

Jeanette Cunningham
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top