Validation (1 Viewer)

moleary

Senior Member
Local time
Today, 21:20
Joined
Feb 9, 2001
Messages
58
I have a form that is used for data entry and I noticed a problem with information not getting on certain reports that I need because of a validation problem, we have codes for all of our locations and within these locations we have codes for the represenative of that location and my queries and reports are based on those codes, but what I am finding is that data entry is not entering the right represenative code and some people aren't getting on the right reports, is there a way I can set it so that when you enter a certain location you can only enter a certain code for that location? example: city1 is code 05 and within city code 05 you can only enter a 01 or 02 for represenative? Please help this is a big problem!
 
In the Before Update event of City1 field use code similar to this:

If Me.City1 <>"01" Or Me.City1 <> "02" Then
MsgBox "Wrong code entered"
Me.City1.Undo
Cancel = True
End if
 
Slight correction. When writing a negative compound condition, you need to use the "And" relational operator rather than "Or". If you analyze the If statement as written the way a computer will, you will see that regardless of the value contained in City1, the result will be true.
 
Ever thought of writing your own book on working with Access Pat? It would have to be a best seller
smile.gif
 
Who has time to write a book. I spend all my spare time here answering questions
smile.gif
 
Slight correction Pat? I think my mistake was much bigger than 'slight' so thank you for being kind in your correction and thank you for catching my error.

Jack
 
So your saying that it should be

if me.city1 <> "01" and me.city1 <> "02" then msg box "wrong code entered" me. city1. undo
cancel=true

now I have more than one location I need to do this for how do I go about that, see we have 8 locations and they are numbered 01-08 and each of them has different reprsenatives:
 
Would I use the same expression for what I want to accomplish?
 

Users who are viewing this thread

Back
Top Bottom