If or then statment

sami4net

New member
Local time
Today, 09:39
Joined
Oct 20, 2010
Messages
6
i want command to open form just if network username = administrator or manager

i try this code but didn't work,

if me.networkusername <> "administrator" or "manager" then
docmd.close
end if

also i tried this one

if me.networkusername <> "administrator" or me.networkusername <> "manager" then
docmd.close
end if

but not efected for second condition
 
In your first attempt you are using the 'or' statement incorrectly, but in your second attempt you are doing it right.
However you are not "looking" at the user's username.

Try this:
if Environ("username") <> "administrator" or Environ("username") <> "manager" then
docmd.close
end if

If that doesn't work, try something like msgbox Environ("username") to see what the user name is that you checking for as that will give you a clue.
 
The statement is still wrong. You need to use AND. The OR operator will only evaluate the first condition. If I log in as "manager" the form will close because it is different than "administrator", thus returning True.
 
The statement is still wrong. You need to use AND. The OR operator will only evaluate the first condition. If I log in as "manager" the form will close because it is different than "administrator", thus returning True.

I use
Code:
If NetworkUserName() = "blah" Or NetworkUserName() = "blah1"
and it works a treat....
 
That is a different statement. The one provided by Freshman is

if Environ("username") <> "administrator" or Environ("username") <> "manager" then

and it will not work.

In your statement you are using "=" so the OR operator works fine
 
That is a different statement. The one provided by Freshman is

if Environ("username") <> "administrator" or Environ("username") <> "manager" then

and it will not work.

In your statement you are using "=" so the OR operator works fine

fair point - must get that appointment with spec savers booked... ;)
He could of course attack from the opposite angle - if it is these users then carry out the function, otherwise close the form.

Now, where's that smiley of a coat being pulled over the face... :)
 
1000 appologies - it comes from scanning over posts too fast and being more concerned about how to check for the user group rather than the user name.

You should just replace the OR with AND as suggested by Scalextric59 right in the beginning.
 

Users who are viewing this thread

Back
Top Bottom