Hello.
The best way to keep the user from leaving a field blank
is to set the "Required" and "AllowZeroLength" properties
in the table definition. By setting Required=True and
AllowZeroLength=False you make Access do the check as the
data is entered.
Also using the form control's ValidationRule and
ValidationText properties will case the check to be done
on the field when the user has changed it's data.
If you need to run a more complex validation on each line
of the form, you can try this code:
DoCmd.RunCommand acCmdRecordsGotoFirst
while not NewRecord
' Validate the fields
' Move to next
DoCmd.RunCommand acCmdRecordsGotoNext
wend
- Or -
Form.RecordsetClone.MoveFirst
do while not Form.RecordsetClone.EOF
' Validate the fields
if not Valid() then
MsgBox "Message"
Bookmark = Form.RecordsetClone.Bookmark
exit do
end if
' Move to next record
Form.RecordsetClone.MoveNext
Loop
The first version cause Access to change the current
record of the form autmatically so that the user can see
which record is currently beeing validated.
Because Access redraws the whole screen, this can be quite
slow, especially if you have a back-end database running
on a network fileserver. The second version will be much
faster because Access will not update the screen unless
finding an error.
Regards,
Ivar Svendsen