A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Validation code



 
 
Thread Tools Display Modes
  #1  
Old March 7th, 2008, 11:26 PM posted to microsoft.public.access.forms
Dave
external usenet poster
 
Posts: 218
Default Validation code

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

  #2  
Old March 8th, 2008, 12:28 AM posted to microsoft.public.access.forms
Steve Schapel
external usenet poster
 
Posts: 1,422
Default Validation code

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 structu

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

  #3  
Old March 8th, 2008, 12:32 AM posted to microsoft.public.access.forms
ruralguy via AccessMonster.com
external usenet poster
 
Posts: 1,172
Default Validation code

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

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


--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200803/1

  #4  
Old March 8th, 2008, 03:44 AM posted to microsoft.public.access.forms
Dave
external usenet poster
 
Posts: 218
Default Validation code

Thank you both.
Worked like a charm

dave

"Dave" dave@accessdatapros wrote in message
...
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


  #5  
Old March 8th, 2008, 07:32 AM posted to microsoft.public.access.forms
ruralguy via AccessMonster.com
external usenet poster
 
Posts: 1,172
Default Validation code

Glad we could help.

Dave wrote:
Thank you both.
Worked like a charm

dave

Access 2003
upon saving a form (date entered on a form)

[quoted text clipped - 22 lines]
Thanks
dave


--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via http://www.accessmonster.com

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:36 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.