Link to home
Create AccountLog in
Avatar of TimHudspith
TimHudspith

asked on

Validation rule for textbox control

My validation rule for a textbox is that the first character must be an underscore, and that underscores cannot be present in the rest of the string. This works in an Access field but not on the form:

=Left([Forms]![Form1]![txtbox],1)="_" And InStr(1,Mid([Forms]![Form1]![txtbox],2,Len([Forms]![Form1]![txtbox])-1),"_")=0
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of TimHudspith
TimHudspith

ASKER

Yes, my expression was convoluted, however when I enter a value in the text box that conforms to the rule it keeps telling me that the validation rule has been broken. Again, it works fine in an Access field.
See the 'General' tab of any Access table in design view. When I use this expression as the validation rule, it works (referencing the fieldname instead of the control).
ok ... when you say 'broken', what does that mean ?  Error message?

mx
can you upload the db or a portion that exhibits the problem ?
Well, I've got it to work at last. It seems an incorrect control reference in the DefaultValue setting of a listbox on the same form was making the functionality of the whole form go haywire.  
 
Thanks for your help.
cool ... cuz I was sort of out of ideas, lol.

mx