Help with code in dropdown box (1 Viewer)

jdp103

Registered User.
Local time
Today, 01:14
Joined
Sep 26, 2003
Messages
46
I have a dropdown box called Status on my form. I want to be able to limit what people can move an item to a specific status. In this case, I only want a PM or Developer to be able to move to the "Development" status. There are only 2 IDs to check for and if their ID comes up, it will let it move to that status, but if not, it will pop up with a message box. I have the code in the "On Change" event of the field. The code works great if I just have one ID, but if I try to do an "OR" and put the other ID, it won't work. Here is my code that works (user1 and user2 in the examples are the developers):

If Status = 7 And cu <> "user1" Then
MsgBox "Only PM or Developer can move to this status. This item will be moved to the status Out For Estimates. Please notify developer.", vbOKOnly
Status = 6
End If


However, if I change to this:

If Status = 7 And cu <> "user1" Or cu <> "user2" Then
MsgBox "Only PM or Developer can move to this status. This item will be moved to the status Out For Estimates. Please notify developer.", vbOKOnly
Status = 6
End If


Then even if your user ID is "user1" or "user2", it gives you the msgbox and it shouldn't. Any ideas? I even tried just using "Or" between the two userIDs and then got a datatype mismatch error.

Any help would be greatly appreciated!
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 22:14
Joined
Aug 30, 2003
Messages
36,139
The OR is not logically correct for your situation. Try "AND" instead:

If Status = 7 And (cu <> "user1" AND cu <> "user2") Then
 

jdp103

Registered User.
Local time
Today, 01:14
Joined
Sep 26, 2003
Messages
46
THANK YOU!! Although I don't really understand why the "Or" didn't work, since logically it should...that fixed it! Thanks again!!!
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 22:14
Joined
Aug 30, 2003
Messages
36,139
No, logically the OR was wrong. It would have been right if you were testing equal instead of not equal. Using not equal (<>) reverses the logic. Imagine you're user2. Since your test was

not equal to user1 OR not equal to user2

user2 is not equal to user1, so user2 passes that test, thus you get the message box. Think about it this way: no matter what user you entered, it's either going to be not equal to user1 or not equal to user2, so everybody gets the message.

You need the AND to test that the tested user is both not user1 AND not user2. Have I clarified it or just muddied the water more?
 

Users who are viewing this thread

Top Bottom