Validation code

D

Dave

Access 2003
upon saving a form (date entered on a form)
I want to look at a field and confirm it is not empty (not looking for
specific data).

I know I need to use an if statement but not really sure of all the syntax

form name = frmDonor
Field Name =last_name

if me.last_name = null Then
MsgBox "You Must Enter a Last Name"
else
DoCmd.GoToRecord , , acNewRec
docmd.close
end if

but this is not working so I have something wrong

ALSO:
If I want more then one field validated - but only one field check at a time
How would I do that

Thanks
dave
 
S

Steve Schapel

Dave,

Try it like this:
If IsNull(Me.last_name) Then

Not sure why you move to a new record and then close the form. If
you're closing, just close, no need for the new record as far as I can see.

If you want to check the entries in several controls, one at a time, you
can use this type of structure:

If IsNull(Me.last_name) Then
MsgBox "You Must Enter a Last Name"
ElseIf IsNull(Me.other_field) Then
MsgBox "You Must Enter a Other Field"
Else
DoCmd.Close acForm, Me.Name
End If
 
Top