I am new to both Access 2003 and VBA and need some help. I have a database I am building and would like to autopopulate the Name controls with the current user that is logged in. I have got the code to capture the current user from the Windows login and made some changes to it. The modual with the GetCurrentUserName= "Tim Peter" and in the form I have a GetCurrentUserID(if GetCurrentUserName is Tim Peter then Get CurrentUserID is 18). I need to find out how to associate the GetCurrentUserID to my Userid in my employee table and populate the name box. Any help would be appreciated.
Here is the GetCurrentUserName:
Option Compare Database
Private Declare Function GetUserName Lib "ADVAPI32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
Public Function GetCurrentUserName() As String
On Error GoTo Err_GetCurrentUserName
Dim lpBuff As String * 25
Dim ret As Long, UserName As String
ret = GetUserName(lpBuff, 25)
UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
GetCurrentUserName = UserName & ""
If GetCurrentUserName = "tpeter" Then
GetCurrentUserName = "Tim Peter"
ElseIf GetCurrentUserName = "tramage" Then
GetCurrentUserName = "Tom Ramage"
ElseIf GetCurrentUserName = "bbrubacher" Then
GetCurrentUserName = "Bob Brubacher"
ElseIf GetCurrentUserName = "wdekock" Then
GetCurrentUserName = "Wayne DeKock"
End If
Exit_GetCurrentUserName:
Exit Function
Err_GetCurrentUserName:
MsgBox Err.Description
Resume Exit_GetCurrentUserName
End Function
Public Function GetCurrentUserID()
If GetCurrentUserName = "Tim Peter" Then
GetCurrentUserID = "18"
End If
End Function
The database is split but the name of the table that has the UserID is [tblemployees]
Thank you for your help.
Here is the GetCurrentUserName:
Option Compare Database
Private Declare Function GetUserName Lib "ADVAPI32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
Public Function GetCurrentUserName() As String
On Error GoTo Err_GetCurrentUserName
Dim lpBuff As String * 25
Dim ret As Long, UserName As String
ret = GetUserName(lpBuff, 25)
UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
GetCurrentUserName = UserName & ""
If GetCurrentUserName = "tpeter" Then
GetCurrentUserName = "Tim Peter"
ElseIf GetCurrentUserName = "tramage" Then
GetCurrentUserName = "Tom Ramage"
ElseIf GetCurrentUserName = "bbrubacher" Then
GetCurrentUserName = "Bob Brubacher"
ElseIf GetCurrentUserName = "wdekock" Then
GetCurrentUserName = "Wayne DeKock"
End If
Exit_GetCurrentUserName:
Exit Function
Err_GetCurrentUserName:
MsgBox Err.Description
Resume Exit_GetCurrentUserName
End Function
Public Function GetCurrentUserID()
If GetCurrentUserName = "Tim Peter" Then
GetCurrentUserID = "18"
End If
End Function
The database is split but the name of the table that has the UserID is [tblemployees]
Thank you for your help.