On a different forum someone asked the following question which to me sounds
like yours. Study it and see if you can adapt it to your situation.
“I am trying to control a form to capture the follow [sic] data:
name, address, zip, tel. If there is no address given (Null) skip zip (let it
be Null) and go to tel. If there is an address zip must not be blank. Any idea
how to nagivate [sic] the form would be much appreciated.”
And this is how I assisted them
One way of achieving your goal is to disable Zip field (On the Properties sheet
of Zip field set Enabled = No) and programmatically enable it only when Address
field is not null.
On LostFocus of Address field write the following code
If Not IsNull(Me.Address) Then
Me.Zip.Enabled = True
Me.Zip.SetFocus
Else
Me.Zip.Enabled = False ‘ just in case it was enabled in the
previous record
Me.Tel.SetFocus
End If
On Lost Focus event of Address write code similar to the following
If Not IsNull(Me.Address) Then
Me.Zip.SetFocus
Else
Me.Tel.SetFocus
End If
On Got Focus of Tel:
If Not IsNull(Me.Address) Then
If Isnull(Me.Zip) Then
MsgBox “Zip cannot be blank…”
Me.Zip.SetFocus
End If
End If
This assumes the user will be using the Enter key on the keyboard. If the user
uses the mouse to move from field to field then, in addition to the above code,
you may wish to write code for BeforeUpdate of the form i.e. check if Zip field
is blank when Address field is filled before saving the record.
If Not IsNull(Me.Address) And IsNull(Me.Zip) Then
MsgBox “Zip cannot be blank …”
Cancel=1
Me.Zip.SetFocus
End If
This ensures that the record is not saved with the missing info.
HTH
Liveson
From: [email protected] [mailto:[email protected]] On Behalf Of
Micro Soft
Sent: Thursday, 06 May, 2010 2:00
To: [email protected]
Cc: [email protected]
Subject: Re: [ms_access] Validation Rule : If you fill in Field1, Field2 is
required also..NOT WORKING
Can Some one please reply..i am in real need of help
________________________________
From: Lonnie Johnson <[email protected] <mailto:prodevmg%40yahoo.com> >
To: [email protected] <mailto:ms_access%40yahoogroups.com>
Sent: Wed, April 28, 2010 6:57:00 PM
Subject: Re: [ms_access] Validation Rule : If you fill in Field1, Field2 is
required also..NOT WORKING
You could put this in your form's Before Update event.
If IsNull(FIELD1) = False And FIELD1 <> "" Then
If IsNull(FIELD2) = True Or FIELD2 = "" Then
FIELD2.SetFocus
FIELD2.BackColor = vbYellow
MsgBox "You must enter a value in Field2", vbCritical
Exit Sub
Else
FIELD2.SetFocus
FIELD2.BackColor = vbWhite
End If
End If
____________ _________ _________ __
From: microaccess80 <microaccess80@ yahoo.com>
To: ms_acc...@yahoogrou ps.com
Sent: Tue, April 27, 2010 12:58:28 PM
Subject: [ms_access] Validation Rule : If you fill in Field1, Field2 is
required also..NOT WORKING
Hello
([Field1] Is Null) OR ([Field2] Is Not Null)is not working for "If you fill in
Field1, Field2 is required" in Both Tables and Forms
I have Fiedl 1 as Blood Pressure Systolic
I have Field 2 as Blood Pressure Diastolic
Both fielda are "number" format
I am not very good with codes, so i am trying validation rules. If simple VBA
codes can work for this, than i can do that. Please help. I am very much in
need. Really hoping for a reply
[Non-text portions of this message have been removed]
[Non-text portions of this message have been removed]
[Non-text portions of this message have been removed]