How to Refer to Current User in VBA (Access 2000)

L

L.A. Lawyer

I am running Access 2000 on a small Windows 98 (and Windows 2000) network.
I want to know the name of the user. How is that done? Do I have to get it
from the registry? How?
 
D

David

-----Original Message-----
I am running Access 2000 on a small Windows 98 (and Windows 2000) network.
I want to know the name of the user. How is that done? Do I have to get it
from the registry? How?


Try this
Option Compare Database

Private Declare Function apiGetUserName Lib "advapi32.dll"
Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As
Long) As Long

Public Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function

then call the function like this example using a MsgBox:

MsgBox "Hello " & fOSUserName

I have a table that stores the time each and every time a
user logs into the application using this function.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top