Environ in IF statement (1 Viewer)

TallMan

Registered User.
Local time
Today, 17:21
Joined
Dec 5, 2008
Messages
239
Hello,

I have the following code that checks to make sure associates, other than myself, are not accessing my Access database from the main share-drive location and that the associates are using a local copy on their desktop. The code was originally writtien so that I - the main developer - could enter the database from the main location. However, I need to add one other associate to have access to open the database from the main location. I cannot get the "OR" statement to work to save my life. Each iteration ends up throwing the message box that is written in the code. I have tried multiple variations with parenthesis, also.

Does this make sense? Thank you in advance for your help.

PHP:
Dim strPath As String
strPath = CurrentProject.Path
 
If ((Environ("Username") <> "user1" And InStr(strPath, "z:\") > 0) Or (Environ("Username") <> "user2" And InStr(strPath, "z:\") > 0)) Then
MsgBox "You are attempting to use the main copy of this database. You need to COPY and PASTE this database to your desktop to create a local reference. The database will now close.", vbExclamation
DoCmd.Quit
End If

PHP:
Dim strPath As String
strPath = CurrentProject.Path
 
If ((Environ("Username") <> "user1" or Environ("Username") <> "user1") And InStr(strPath, "z:\") > 0) Then
MsgBox "You are attempting to use the main copy of this database. You need to COPY and PASTE this database to your desktop to create a local reference. The database will now close.", vbExclamation
DoCmd.Quit
End If
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 14:21
Joined
Aug 30, 2003
Messages
36,126
Try And instead of Or.
 

TallMan

Registered User.
Local time
Today, 17:21
Joined
Dec 5, 2008
Messages
239
Thanks, Pbaldy. THis worked. I am not sure why, but it worked. Logically it does not make sense to me. Thanks again!

Tallman
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 14:21
Joined
Aug 30, 2003
Messages
36,126
No problem. The logic reverses because you're using <> instead of =. Every user is either not user1 OR user2. You want if it's not user1 AND it's not user2.
 

Users who are viewing this thread

Top Bottom