>>any new way to write this code under , and at click or keypres is better
>>IF thisform.text2.value=ALLTRIM("Residential") AND thisform.text1.Value < 1 OR thisform.text1.Value>5
> =MESSAGEBOX("out of range")
> thisform.text1.SetFocus
>ENDIF
>IF thisform.text2.value=ALLTRIM("Business") AND thisform.text1.Value < 1 OR thisform.text1.Value>4
> =MESSAGEBOX("out of range")
> thisform.text1.SetFocus
>ENDIF
>
>thanks.Normally you do that in the Valid() method. Or as a last resort in LostFocus().
If ThisForm.Text1 only gets a simple number with a range of 2-4 why don't you change it to a Spinner control setting the Min and Max properties to 2 and 4?
Also when mixing AND and OR comparisons in the same line you have to use parenthesis:
IF a AND (b or c)
else you'll get incorrect results.
As an aside, it is generally better (more self-documenting) to change the name of the controls to something meaningful instead of "text1" and "text2". Makes you program easier to read and understand.