I do not know if you have your answer. I had the same problem, this is what I
did and, yes, it works. Maybe not the best solution...
Create the following module, I copied from it from thread in this support
group:
Option Compare Database
'******************** Code Start **************************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
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
'******************** Code End **************************
Create a form (UserName in my case) that will open when you open the
database file, set its property to hidden. Create a textbox (pUserName in my
case) and type the following coding in the [Open] event. You can refer to the
user name by: [Forms]![UserName]![pUserName]
Each "Case" is the login name, pUserName = "Anything you want"
Private Sub Form_Open(Cancel As Integer)
'*********************************************************************
'* *
'* This coding grabs the current Network UserName *
'* *
'* The textbox [pUserName] is the criteria used in the User queries *
'* *
'* The Coding for the function fOSUserName()is Module 1 *
'* *
'*********************************************************************
Dim Temp As String
Temp = fOSUserName()
Select Case UCase(Temp)
'------------------
Case "IDELUNA"
pUserName = "IVO"
'------------------
Case "ALORENZO"
pUserName = "AMA"
'------------------
Case "DDAVIS"
pUserName = "DAN"
'------------------
Case "BHOFACKER"
pUserName = "BRI"
'------------------
Case "MROBERTS"
pUserName = "MEL"
'------------------
Case "CLEWIS"
pUserName = "CAR"
'------------------
Case "WINADMIN"
pUserName = "MEL"
'------------------
Case Else
MsgBox vbCrLf & vbCrLf & _
" ****** You are NOT authorized to access this file ******" &
vbCrLf & vbCrLf & _
" This application will terminate NOW..." & vbCrLf &
vbCrLf & _
"===================================", 0, " ******
UNAUTHORIZED USER *******"
Application.Quit
'------------------
End Select
End Sub
You can refer to the user name by: