Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Replace System Error Message with My Own!! 1

Status
Not open for further replies.

khwaja

Technical User
Aug 27, 2001
431
0
0
AU

I have a form based on a table with EmployeeID as the PK and the Location/Region property set to required.

In my form, user has to start by indicating the Location/Region first (located in the report header) and then moves on to filling the rest of the record. EmployeeID is text field and comprises a prefix alphabet followed by 6 digits.

I have noticed that after filling in the Location field, if user aborts the record for some reason, he is presented with a very unfriendly system message that "The field tblEmployee.EmployeeID can't contain null value because the Required property for this fields is set to True. Enter a value in the field".

Is there some way I could substitute the system error message with the one created by me?

I am using Access 97.

Thanks in advance for your help.
Cheers

AK
 
In your form, modify the EmployeeID control properties, in Data tab:
Validation Rule => Not Is Null
Validation Text => Please enter a value

When the validation rule is not respected, then the validation text is displayed.
 
Try to improvize on the following


Sub yourSub (your conditions)
On Error GoTo MyError

your subContent

ExitSub:
Exit Sub

MyError:
Mymsgbox=MsgBox (yourMESSAGE,additional stuff after coma,,,)
Resume ExitSub
Good luck,
Kuzz

"Time spent debating the impossible subtracts from the time during which you
can try to accomplish it."
 
Thanks TorF and Kuzz.

Re TorF's solution, despite using the validation rule, it still comes back with the system message as the record was attempted to save after entering the Location first. So there is a need for a message to appear I guess in the After Update event of Location field which then goes on to check if the employee ID has been entered and if not, an error message appears. I am not too sure whaty code to use.

Kuzz, thanks for the template. Just wondering if this code is intended to be tied to employeeID field or the Location field and what needs to be tested? Could this be After Update event of one of these fields? Will appreciate a little help with this.

Cheers

AK
 
In the form BeforeUpdate event, check if tblEmployee.EmployeeID is null. In this case display your message and cancel update.

That should be something like:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.EmployeeID ) Then
MsgBox "Please my message"
Cancel = True
End If
End Sub
 
Thanks a lot guys. Helpful lot as usual. Cheers

AK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top