UserID

Jmsteph

Registered User.
Local time
Today, 07:00
Joined
Dec 2, 2008
Messages
28
I have a database that checks the userid that the person used to log into the PC to get into the database. It have worked for many people for many years, but all of the sudden it is failing on a new associate. Does anyone know where VBA actually pulls the users ID as I'm thinking IT set her up incorrectly.
Thanks,

Jeremy
 
It depends on how your database is set up. The database could be using the VBA.Environ("username") syntax or it could be using the Windows API. Or it could be using Active Directory for this. Hard to say without seeing the database.
 
I don´t mean to hijack your thread, but I also have a question on UserID, the answer to which may also help you! :D

My database runs on Win XP machines and uses the following code to find the UserID:-

Dim stUser As String
Dim wsh
Set wsh = CreateObject("WScript.Shell")
stUser = wsh.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Logon User Name")

This was fine until now when we have a new PC running Win 7. This code doesn´t work on Win 7. Is there a better way of finding the UserId of the signed on person or does anyone know the Win 7 equivalent code.

I would also need the code to identify the Win version running on the PC of course!!
 
You should not be accessing the registry directly to get user login information. You can use the

VBA.Environ("username")

code but if you want to ensure that nobody can spoof someone else (because a knowledgeable user can change the environment variable easily enough if they know what to do) then you can use this Windows API here:
http://access.mvps.org/access/api/api0008.htm
 
Hi Bob,

I use the the modual below.

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
Declare Function clt_OpenClipboard Lib "User32" Alias "OpenClipboard" (ByVal hwnd As Long) As Long
Declare Function clt_EmptyClipBoard Lib "User32" Alias "EmptyClipboard" () As Long
Declare Function clt_CloseClipboard Lib "User32" Alias "CloseClipboard" () As Long

Then I use the below code so that I can call it in VBA.

Public Property Get UserName() As Variant
Dim sBuffer As String
Dim lSize As Long
sBuffer = Space$(255)
lSize = Len(sBuffer)
Call GetUserName(sBuffer, lSize)
UserName = Left$(sBuffer, lSize - 1)
End Property

This allowes me to pull a users ID by calling UserName() in the VBA code. This has always worked for me, but I now have a user that is not matching what I have listed for her network ID, do the database is denying her access as I block anyone who's ID is not in the auth table.
 

Users who are viewing this thread

Back
Top Bottom