- Local time
- Today, 09:36
- Joined
- Jan 23, 2006
- Messages
- 15,573
I split your sample database and created tblUserDemo in the BE.
tblUserDemo tblUserDemo
I added this code to the top of your module1 and am using FOSUserName to get the user short name automatically and use that result to get ActualUserName for tblUserDemo.
' ----------------------------------------------------------------
' Procedure Name: GetRealUserName
' Purpose: Demo Function to get ActualUserName from tblDemoUser via CompUserName
' Procedure Kind: Function
' Procedure Access: Public
' Return Type: String
' Author: Jack
' Date: 10-Jan-24
' ----------------------------------------------------------------
Function GetRealUserName() As String
Dim UserShortName As String
'use FOSUserName to get actual computer user name
UserShortName = fOSUserName
'Lookup ActualUserName from tblDemoUser using UserShortName
GetRealUserName = DLookup("ActualUserName", "tblUserDemo", "CompUserName='" & UserShortName & "'")
End Function
Testing:
?fosusername
JP
?GetrealUserName
That’s Me
tblUserDemo tblUserDemo
| UserID | CompUserName | ActualUserName | OtherUserSpecificInfo |
|---|---|---|---|
1 | kl | kanth Thpell | anndr998 |
4 | mc | My Kat | purr |
3 | qr | Queen Resource | |
2 | jp | That’s Me | demo |
I added this code to the top of your module1 and am using FOSUserName to get the user short name automatically and use that result to get ActualUserName for tblUserDemo.
Code:
#If VBA7 And Win64 Then
'x64 Declarations
Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long
#Else
'x32 Declaration
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long
#End If
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
' ----------------------------------------------------------------
' Procedure Name: GetRealUserName
' Purpose: Demo Function to get ActualUserName from tblDemoUser via CompUserName
' Procedure Kind: Function
' Procedure Access: Public
' Return Type: String
' Author: Jack
' Date: 10-Jan-24
' ----------------------------------------------------------------
Function GetRealUserName() As String
Dim UserShortName As String
'use FOSUserName to get actual computer user name
UserShortName = fOSUserName
'Lookup ActualUserName from tblDemoUser using UserShortName
GetRealUserName = DLookup("ActualUserName", "tblUserDemo", "CompUserName='" & UserShortName & "'")
End Function
Testing:
?fosusername
JP
?GetrealUserName
That’s Me