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

Validations

Status
Not open for further replies.

Seeff

Programmer
Dec 2, 2002
33
IL
I have a form with two text boxes. The first determines the valid values for the second.
For example:
Text1 can be A or B.
If text1=A then Text2 can have values of 1,2,3. If text1=B then text2 can have values of 10,20,30. How do I approach this and where? I want the form to be "stuck" until valid values are entered.

Thanks in advance to all those who reply.
 
not too difficult in fact...

You create the form with two textboxes and then a button to continue.
In the button to continue you put

sub Continue_OnClick()
If Me!Text1.Value = A then
If Me!Text2.Value = Val1 or Me!Text2.Value = val2 then
'continue code
end if
elsIf Me!Text1.Value = B then
If Me!Text2.Value = Val3 or Me!Text2.Value = val4 then
'continue code
end if
end if
end sub

If the values required are not found you won't do the continue code and the form will not change

Chirpy

*- Stars always welcome -*
 
The form has a whole lot of buttons and the user can navigate between records too. I would like the data entry to be checked immediately.I will complicate it a little.

The first values can be a,b,c,d (group1)OR e,f,g,h (group2).
If group1 then valid values are 1,2,3,4,5.
If group2 then valid values are 6,7,8,9,10.

 
Sorry....I messed it up. It's like this

The first values can be a,c,e,g (group1)OR b,d,f,h (group2).
If group1 then valid values are 1,2,3,4,5.
If group2 then valid values are 6,7,8,9,10.

 
It's the same thing but you will do
sub Continue_OnClick()
If Me!Text1.Value = "a" or "c" or "e" or "g" then
If Me!Text2.Value > 0 and Me!Text2.Value <= 5 then
'continue code
end if
elsIf Me!Text1.Value = &quot;b&quot; or &quot;d&quot; or &quot;f&quot; or &quot;h&quot; then
If Me!Text2.Value > 5 and Me!Text2.Value < 11 then
'continue code
end if
end if
end sub




*- Stars always welcome -*
 
Thanks Chippy for your time.

I don't want a button. Ok...I got the if checks going and determine if the values are valid or not. Then what?
If they not then what do I do to force the user to stay put until a correct value is entered?
Which event do I use? AfterUpdate?
 
Instead of OnClick of the button you put the code into a function then you do OnUpdate for the 2 textboxes
Sub Text1_OnUpdate
call checkfunction
end sub

Sub Text1_OnUpdate
call checkfunction
end sub

If the continue code is not called in the check function they will rest where they are you could do :

private function checkfunction()
If Me!Text1.Value = &quot;a&quot; or &quot;c&quot; or &quot;e&quot; or &quot;g&quot; then
If Me!Text2.Value > 0 and Me!Text2.Value <= 5 then
'continue code
Else
msgbox &quot;Valid values are 1,2,3,4,5 in Text2&quot;
end if
elseIf Me!Text1.Value = &quot;b&quot; or &quot;d&quot; or &quot;f&quot; or &quot;h&quot; then
If Me!Text2.Value > 5 and Me!Text2.Value < 11 then
'continue code
Else
msgbox &quot;Valid values are 6,7,8,9,10 in Text2&quot;
end if
Else
msgbox &quot;Valid values are a-h in Text1&quot;
end if
end function





*- Stars always welcome -*
 
Thanks Chirpy...it works with a few changes of course. Something in the Elseif was bad.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top