Validation code

  • Thread starter Thread starter Dave
  • Start date Start date
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
 
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
 
You would do this sort of validation in the BeforeUpdate event of the form.
The example you used would be:

If Len(Me.last_name & "") = 0 Then
MsgBox "You Must Enter a Last Name"
Cancel = True '-- to cancel the SAVE
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top