Re: Validation code

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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

--
Steve Schapel, Microsoft Access MVP

Dave wrote:
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
.



Relevant Pages

  • Re: Cancel Printing Except Q
    ... Thanks Dave, I got around it as in my real data I had more than one ... Dim myArr As Variant ... MsgBox "Don't print it" ...
    (microsoft.public.excel.programming)
  • Re: How do I force an Excel macro to ask me which file and directory?
    ... Dohhhhhhh - Cheers for the catch Dave :-) ... > MsgBox "Canceled" ... >> It's easier to beg forgiveness than ask permission :-) ...
    (microsoft.public.excel.misc)
  • Re: I think Im missing something!
    ... Dim Dave As ObjKind ... MsgBox "Object is a Printer" ... If Not HasErrored Then Exit Function ... If SomeObject.AutoSize> -1 Then WhatObject = ItsPictureBox ...
    (microsoft.public.vb.general.discussion)
  • Re: add comment to object
    ... Dave: Thanks for your responses. ... The first response would work, ... The MsgBox was an option, however I have not made professional ... "Dave Peterson" wrote: ...
    (microsoft.public.excel.programming)
  • Re: Declaring Objects
    ... > "Dave Peterson" wrote: ... >> MsgBox oColors.Address ... >>> which although it looks as though it picks two separate areas it ... >> Dave Peterson ...
    (microsoft.public.excel.programming)