Once again, the validation code
Code:
Dim Ctrl As Control
For Each Ctrl In Me.Controls
If Ctrl.Tag = "*" And IsNull(Ctrl) Then
MsgBox "A required data entry has not been made - please check fields with * are filled in"
Cancel = True
Ctrl.SetFocus
Exit For
End If
Next Ctrl
Needs to be in,
and only in, the
Form_BeforeUpdate event!
As I think I've said, I've never used this particular
Validation code, employing the
Tag Property, but it looks doable.
You don't need
validation code in the '
Close'
Button! When the
Form goes to close, the
Form_BeforeUpdate event, with its
validation code, will run. All you need your
Button to do is start the closing process.
In point of fact, you really don't need a '
Close'
Button! Moving to another
Record, closing the Form, or closing Access itself, will start the
validation process. If you insist on a '
Close'
Button, all the code you need in it is
Code:
If Me.Dirty Then Me.Dirty = False
DoCmd.Close
The first line
If Me.Dirty Then Me.Dirty = False
is needed because of a long standing bug in Access. When the line
DoCmd.Close executes, to close a
Form thru code, it does so without regard as to
- Whether or not Validation Rules have been violated
- Whether or not Required Fields have been left blank
If either of these conditions are true, Access will merely
dump the Record,
without any warning, and close the
Form! Setting
Me.Dirty to
False, if it currently
Is Dirty, forces a
Save and starts the
Validation Process in
Form_BeforeUpdate, as well as enforcing
PK/Required Field rules.
As for a
Button to simply dump the
Record, in order to return to your previous menu
Form, all you need is Sinndho's code from
Post # 2.
If you're still having problems, you know where we are!
BTW,
we're all still learning! No matter how long we've been doing this!
Linq
;0)>