Hell666,
Welcome to Bytes.com.
I've moved as much of your question as possible in to your post from the title and added the mandatory [code][/code] tags
To be honest, if you want the [Gender] field to be mandatory, IMHO, your best solution is to implement this at the table level by setting the "required" property to "Yes" and setting up some validation rules to ensure that only valid data is entered, along with a custom error message that triggers from the table. IMHO this works better in that VBA doesn't need to be enabled (don't get me wrong, VBA is my stock and trade with Access databases, but why use a Jack-hammer when a rolled up piece of newspaper will do the job?).
Your second best option would be the
Before_Update
event of the FORM, not the
After_Update
The
Before_Update
event will allow you to cancel the save or update of the record while allowing the user to [ESC] to abort the record entry or update. Best thing here is that the user can't go back to older entries and attempt to delete the value in that field and save the record.
A VERY simple example would be:
- Private Sub Form_BeforeUpdate(Cancel As Integer)
-
If ((Me.Gender & "") = "") Then
-
MsgBox "Sorry please enter a Gender for this record"
-
Cancel = True
-
End If
-
End Sub
This needs a lot more code such making sure the [ctrl_Gender] receives the focus, only the proper values are entered (ideally, these should be validated at the table level either with validation rules or by design) error trapping, etc...