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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Access DB to return current user 1

Status
Not open for further replies.

murrry

Technical User
Sep 25, 2002
9
0
0
US
Hello all. I've been tweaking my database for weeks it seems and I keep coming up with things to add to it.

Here's my question: On my main form I'd like to have a field that is automatically populated with the current user's logon name. And I'd like for that value to be stored in the table. Does anyone know an easy way to accomplish this or do I have to resort to code?

Any suggestions would be fantastic at this point!
Thanks,
Mary
 
Below is an API call:

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Use the API like this:

Public Function UserName() As String
Dim sBuffer As String
Dim lSize As Long

sBuffer = Space$(255)
lSize = Len(sBuffer)
GetUserName sBuffer, lSize
UserName = Left$(sBuffer, lSize - 1)
End Function
 
Add a field in your table to store the logon name and set it's default value to
=Environ("username")
 
Thanks to you both for the help. But I admit I took the easy way out with Rick39's suggestion. And it did exactly what I needed! Thanks again for the suggestions!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top