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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Field Validation

Status
Not open for further replies.

bigmerf

MIS
Oct 4, 2002
247
0
0
US
I have a form that has about 6 fields. I want to be able to force, or validate, that the user enters in a value greater than "0" based on the value of another fields.

For instance:

If Text40 > 0 then
force a value > 0 for field Text50

Essentially that's what I want to do. Where would I enter that in on? The field validation within "Properties"? If so how could the code be written??

Please help!
 
Hi WLTC,

Cross-field validation of that sort would normally be coded in the Form BeforeUpdate Event.

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
There are lots of options here. First make the field in the table be a value and a non-zero value. Then do a doubleclick event on the textbox in question and tell the user what is acceptable and not, enter the value and place it in the other text box. I know, clear as mud. email for a sample with the above description in the email so I can commect with the thread. Then I will send you back a sample and post it.

rollie@bwsys.net
 
I'm not sure I understand... I figured the code would be in the BeforeUpdate section of the form, and that's fine. The trouble I'm having is coming up with the code to validate. Can you actually use an "If" statement within the validation Rule of a field?

My code currently looks like this, and may be way off:

If Text40 <> 1 then //&quot;1&quot; is the default value
me.text50.value > 0 //make text50 validated > 0

I'm getting an error when entering data. The code isn't compiling correctly.

Can you help with this?
 
WLTC,

try Putting this in the AfterUpdate of Text40:
**************
Text41.SetFocus
**************

Put this in the LostFocus of Text41

****************************************************
If Text40 > 1 And Text41.Value = 0 Then
MsgBox &quot;This field cannot be zero&quot;, vbOKonly
Text41.SetFocus
Else
End If
****************************************************
Note: Text41 is what ever field needs the input. You can put any message that you want in the MsgBox.

This will not let the user get past the text box that needs the input.

good luck
 
Your problem here is that you are trying to set a variable

me.text50 = >0

I do not know what that means. Neither does the compiler. If I said you must give me greater than 50 what would you give me. You are trying to set the value and not the valid values.

rollie@bwsys.net

 
Resubmit

WLTC,

try Putting this in the AfterUpdate of Text40:
**************
Text50.SetFocus
**************

Put this in the LostFocus of Text50

****************************************************
If Text40.Value > 1 And Text50.Value = 0 Then
MsgBox &quot;This field cannot be zero&quot;, vbOKonly
Text41.SetFocus
Else
End If
****************************************************
Note: You can put any message that you want in the MsgBox.

This will not let the user get past the text box that needs the input.

good luck


Sorry about that
 
Resubmit again

WLTC,

try Putting this in the AfterUpdate of Text40:
**************
Text50.SetFocus
**************

Put this in the LostFocus of Text50

****************************************************
If Text40.Value > 1 And Text50.Value = 0 Then
MsgBox &quot;This field cannot be zero&quot;, vbOKonly
Text50.SetFocus
Else
End If
****************************************************
Note: You can put any message that you want in the MsgBox.

This will not let the user get past the text box that needs the input.

good luck


Sorry about that

Man I'm an idiot
 
That worked &quot;ancb&quot;! Thanks so much for your help. The whole time I was trying to put that statement in the &quot;validation Rule&quot; portion of the field. I really should of thought of that myself.

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top