Limiting a field to a particular string

canjfn

Registered User.
Local time
Today, 00:01
Joined
Apr 24, 2001
Messages
28
On My form I would like to have code to limit what can be put into a field e.g

If Me.Myfield is not = to A, B or C
then
message
"You must enter A, B or C in this field"
EndIf

Any help please ?
 
Use a ComboBox with RowSourceType set to ValueList and Limit to list set to yes.
 
RuralGuy's suggestion is the best method buy just FYI, I'll show you the correct If statement:

If Me.Myfield not = to "A" AND Me.Myfield not = "B" AND Me.Myfield not = "C" then
 
Hi Pat,

I think someone we both know must be sleepy.
If Me.Myfield not = to "A" AND Me.Myfield not = "B" AND Me.Myfield not = "C" then
How about:
Code:
If Me.Myfield <> "A" AND Me.Myfield <> "B" AND Me.Myfield <> "C" Then

Merry Christmas!
 
Wouldn't a 'not in()' statement be more elegant
 
I think someone we both know must be sleepy.
That's what happens when you answer questions in your sleep:) Thanks for fixing it.

Wouldn't a 'not in()' statement be more elegant
True but we had already suggested that the combo was a better solution so I didn't want to confuse the issue. The entire point of my post was to show the syntax for a complex compound conditional statement because most people have such trouble with them. English syntax and boolean syntax are different and no one seems to teach boolean logic any more. However, I failed miserably since I was sleeping when I copied and pasted the code :(
 
Last edited:
Hi Pat. I wasn't trying to be clever. I would use a combo, too. I just get frustrated when my colleagues use extended statements (usually in Excel, however) that replicate built in functions. I guess I have my eyes tuned for that kind of thing.
 

Users who are viewing this thread

Back
Top Bottom