Private Sub Approved_AfterUpdate()
If Me.Approved = True Then
Me.Approved_by = DLookup("ID", "Users", "Login =" & "'" & GetUserName & "'")
Debug.Print Me.Approved_by
End If
End Sub
Option Compare Database
Option Explicit
Private 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
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
GetUserName = Left$(strUserName, lngLen - 1)
Else
GetUserName = vbNullString
End If
End Function
? DLookup("[ID]", "[Users]", "[Login] =" & "'" & GetUserName & "'")
Private Sub Approved_AfterUpdate()
If Me.Approved = True Then
'Me.Approved_by = DLookup("ID", "Users", "Login =" & "'" & Nz(GetUserName) & "'")
Me.Approved_by = Nz(DLookup("ID", "Users", "Login ='" & Nz(GetUserName, "") & "'"))
Debug.Print Me.Approved_by
End If
End Sub
Are you trying to get the Current Windows user name? If yes, try this: http://access.mvps.org/access/api/api0008.htm
Otherwise it would help to see the code for use are using for your "standard" GetUserName function