AutoExec - check Environ("USERNAME")

billy2345

New member
Local time
Today, 07:45
Joined
Sep 20, 2007
Messages
4
I am trying to put together some code that will check the username upon opening the db. If the username matches, then the db stays open, otherwise it closes.

Public Function StartUp1()

If Environ("USERNAME") = xxxxxxx Then

Else

MsgBox ("Sorry :(")

Application.Quit

End If

End Function
 
sorry......just walked back to the pc.....did not know i posted already.

Question is the code does not work, so how would i go about this? The msgbox comes up regardless of the user.
 
sorry......just walked back to the pc.....did not know i posted already.

Question is the code does not work, so how would i go about this? The msgbox comes up regardless of the user.

What are you checking Environ("username") against?

Is the xxxxxxx value you have hard coded? If so where did you get that value from? The Environ("username") will return the windows logon id, so make sure you are using that ID to do your verification.
 
okay, so if my windows id is TEST01, and I have Environ("username") = TEST01 it should theoritcally recognize it?

I have tested with my windows id, and it does not work. Is there a particular mode I need to have the db run in?
 
okay, so if my windows id is TEST01, and I have Environ("username") = TEST01 it should theoritcally recognize it?

I have tested with my windows id, and it does not work. Is there a particular mode I need to have the db run in?

You would need quotes around "TEST01" otherwise it will think TEST01 is a variable.
 
Hay Billy,

Have you tried just transfering the usernme into a text box to see what it is?
ie
[Forms]![firstform]![test] = Environ("UserName")

Garry
 
I put the Environ("UserName") into a table then Created a SQL with a Where:

WHERE Users.[Login] = Environ$('UserName')

If the rs.recordcount = 0 you can then decide how punitive your next action is!

Simon
 

Users who are viewing this thread

Back
Top Bottom