Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate two fields on a form 2

Status
Not open for further replies.

Ezeasy

MIS
Feb 7, 2002
37
US
Not sure what to do new to access and where do you put the code. I want to validate two fields on my form but only one need to have data. For example if (field1 is blank and field2 is blank) send a message “field1 or field2 must have data” else one of them have data which is ok. Thanks in advance for any help.
 

Since you are checking more than just one field you would want to do this in the forms before update event. Your code would look something like this.

If nz(me.field1.value) = 0 and nz(me.field2.value) = 0 then
Msgbox “You must enter either field1 or field2”,vbcritical
Cancel = true
Me.field1.setfocus
End if

Setting cancel = true will cancel the update of your record.
Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
Which field do you put the code on. Will I have the ability to enter data in either field again or do you start keying the whole form again.
 

As I told you, the code does not go on a field since in Access you can start with field2 and not return to field1. You put the code in the forms before update event. The code snip I gave you will position the cursor to field1. At that point the user can do whatever they want. The assumption is they will correct the error and resubmit the form.
Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top