How to get user Logon ID in Access

D

Dean Slindee

I would like to store the user's logon ID in a record when inserting or
changing a record.

Putting a couple of invisible text boxes on the form would work, but how do
I get the user's ID in Access?



Thanks,

Dean Slindee
 
L

Luther

Hi Rob:

Just the question I was about to ask. This is a nice module, but I would
like to be able to substitute the person's real name in the text box on the
form. Is that possible? In other words, once the user open the form, the
field is automatically populated with their name (of course, this DB has a
limited number of users that I know).

Thanks in advance for your help.
 
R

Rob Oldfield

I'd generally do that by just having a table listing network name and full
name. Then just use the value from the code to run a lookup to find the
full name.

I believe that it should be possible (at least theoretically) to grab a
user's active directory full name using ldap queries but I've had no success
with those (and that's in .Net instead of Access where I'd guess it'd be
even harder)
 
L

Luther

I think the table solution is the easiest. How would I get the value of the
code into a lookup expression on the form? I am not sure I can see a field
name in the module...
 
R

Rob Oldfield

Nooooooooooooooooooooooooooo!!!!!!!!

Do you know how long I spent with those *!%&**!% ldap queries trying to get
that?

<Goes away to find a small dog to kick>
 
R

Rob Oldfield

Doug's idea is better, but it would just be something like...

dlookup("[FullName]","UserTable","[LoginName]='"+fosusername()+"'")
 
L

Luther

Thank you so much, everybody !!!!!

Rob Oldfield said:
Nooooooooooooooooooooooooooo!!!!!!!!

Do you know how long I spent with those *!%&**!% ldap queries trying to get
that?

<Goes away to find a small dog to kick>
 
R

Ricoy-Chicago

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:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top