Polling Internal user account using VB

  • Thread starter Thread starter requeth
  • Start date Start date
R

requeth

Hello,

I currently have a database that has two types of users built in (using
the access system). Only two actual usernames are created of "admin"
and "user". I also have a module that polls the operating system to get
the windows user, as well as time, and date. Since multiple people will
have access to the admin user, I would like to log the login type to my
login log. How would I poll the access username? If it helps I attached
my module code below.

Option Compare Database

Public Declare Function apiGetUserName Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function GetUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
Dim v_user As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
GetUserName = Left$(strUserName, lngLen - 1)
Else
GetUserName = ""
End If
v_user = GetUserName
sqlInsertStatement = "Insert into
UserLog([UserName],[LoginDate],[LoginTime]) Values('" & v_user & "','"
& Format(Date, "mm\/dd\/yyyy") & "','" & Time & "')"
DoCmd.SetWarnings False
DoCmd.RunSQL sqlInsertStatement
DoCmd.SetWarnings True
End Function
 
Hello,

I currently have a database that has two types of users built in
(using the access system). Only two actual usernames are created of
"admin" and "user". I also have a module that polls the operating
system to get the windows user, as well as time, and date. Since
multiple people will have access to the admin user, I would like to
log the login type to my login log. How would I poll the access
username?

Use the CurrentUser() function.
 
Back
Top