Msg if Required filed not entered

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I write custom global message box to warn when users try to skip a
required record so i can use it on several forms?
Some step by step guide or tips will be very much appreicited....

Thanks
 
There are 2 cases to consider:
a) User starts entering something in a control, and backspaces it out.
This triggers the Error event of the form.

b) User tries to save a record without entering a required field.
This can be trapped in the BeforeUpdate event of the form.

You will therefore need 2 procedures, and call them from the 2 events of
each form. The form's Error event fires whenever an engine-level error
occurs. Its DataErr argument will be 3201 for the required field error.
Other examples you might want to consider for this routine:
2113: Wrong type of data
3022: The record cannot be saved, as it would create a duplicate
3201: A related record is required.
An issue with trying to design your own custom message is knowing which
field caused the error. Screen.ActiveControl might give you that, but there
are issues here with subforms and where the error was triggered by
programmatically assigning a value to a control.

The second case probably cannot be written generally. If you want to catch
the error before it occurs, you will need to explicitly test each required
field in Form_BeforeUpdate. If you don't do that, the error number that
results from the failed save can be *very* wide. If you explicitly save with
code such as:
Me.Dirty = False
the error numbers can be 3314, 2101, 2115, and so on. If you do not
explicitly save, some of the error messages are quite generic (e.g. "The
command is not available now", or "You cannot move at the moment"), and
others are quite spurious/unhelpful (e.g. "You tried Update without an Edit
first")

What I personally do is to call a generic function in the Error event of all
bound forms, but write a specific validation routine in the BeforeUpdate
event of every form.

Hope that helps.
 
Thanks Allen,
I will use your tips and work on it over the weekend and see what i can come
up with...
Thanks
 
Back
Top