Dear Chrisso,
I'm not an expert, but I know 2 ways of doing this. First is you set up a
MDW using security wizard. After that, you could use "Current User." Second
is to get the window login using the the below code.
Option Compare Database
Declare Function WNetGetUser Lib "mpr.dll" _
Alias "WNetGetUserA" (ByVal lpName As String, _
ByVal lpUserName As String, lpnLength As Long) As Long
Const NoError = 0 'The Function call was successful
Function GetUserName() As String
Dim LUserName As String
Const lpnLength As Integer = 255
Dim Status As Integer
Dim lpName
' Assign the buffer size constant to lpUserName.
LUserName = Space$(lpnLength + 1)
' Get the log-on name of the person using product.
Status = WNetGetUser(lpName, LUserName, lpnLength)
' See whether error occurred.
If Status = NoError Then
' This line removes the null character. Strings in C are null-
' terminated. Strings in Visual Basic are not null-terminated.
' The null character must be removed from the C strings to be used
' cleanly in Visual Basic.
LUserName = Left$(LUserName, InStr(LUserName, Chr(0)) - 1)
Else
' An error occurred.
MsgBox "Unable to get the name."
End
End If
GetUserName = LUserName
End Function
code if from Access 2003 VBA Programmer's Reference, Wrox. Wiley Publishing,
Inc.