About Robert Austin Expertise I can answer questions relating to database design, User Interface design, Visual Basic and VBA coding and Reporting Design, as well as intermediate level SQL query statements.
Experience I have been creating MS Access databases since version 2.0, for almost 20 years.
Education/Credentials Most of my technical training has been on-the-job, but I have almost completd my Bachelors of Science in Technology Management at DeVry University.
Question I have a field that I want to auto-populate with the Windows username of the current user when they create a new record. The field is "UserName" with in a form. there are no users for this database as they are all opening the DB with the Access 2007 runtime if I use Currentuser() I always get Admin (obviously) how can I get the windows username?
Answer Create a module wtih the following code (or add to an existing one).
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
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
Then, to get the user name, you could fill a variable with it,