Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get current logged on user

Status
Not open for further replies.

Dbyte

Technical User
Mar 6, 2002
87
0
0
Am trying to have a textbox on my form auto-populate with the ID of the user currently logged onto the PC when the form is opened. I created a module w/ the following code from faq702-4949:
Code:
Public Function GetUserName_TSB() As String
On Error GoTo error_handler
Dim lngLen As Long
Dim strBuf As String
Const MaxUserName = 255
strBuf = Space(MaxUserName)
lngLen = MaxUserName
If CBool(TSB_API_GetUserName(strBuf, lngLen)) Then
  GetUserName_TSB = Left$(strBuf, lngLen - 1)
Else
  GetUserName_TSB = ""
End If
Exit Function
error_handler:
Error_Recorder
End Function

I have a textbox in my form w/ the following in Before Update:
Code:
GetUserName_TSB ()

The text box is blank when I view the form.
 
In the Load event procedure of the form:
Me![your textbox] = GetUserName_TSB()

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV, I got the following error when I added your command to the On:
Microsoft Office Access can't find the macro 'Me!ITStaff=GetUserName_TSB().'

I double-checked: GetUserName_TSB is saved as a module (not a macro) & consists of only the code I pasted above.
 
In the Load event [!]procedure[/!] of the form:
Me![your textbox] = GetUserName_TSB()

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OK, added the following as the Load event procedure:
Code:
Private Sub Form_Load()
Me![ITStaff] = GetUserName_TSB()
End Sub

After adding this when I open the form I get the following error message: "Compile error: expected variable or procedure, not module
 
Seems you have given the same name to the module and the function ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top