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

linking username to actual name

Status
Not open for further replies.

tizwaz

Technical User
Aug 8, 2002
437
GB
I am trying to build a database and want to base several things on who is the logged in user. I have found the following code (in someone elses dbase) and that seems to give me the username. However I need to match that up with the actual name of the person to auto filter and auto complete certain forms etc. I have made a table (calledTblLogin) with the fields username and actual name but don't know how to link it to the code I have. Ideally I would like the currently logged in user's actual name to be available as a global variable. Can anyone help point me in the right direction?

Code

Option Compare Database


Public 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

 
smoething like this placed in a module should do it for you

function Realname() as string
realname = dlookup("[actual name],"calledTblLogin", "username = '" &fOSUserName & "'" )

end function

will need to edit the dlookup to match you tables fields but should be close

Also would be better using a recordset but dlookup will get it for you
 
You can use this function as criteria in a query....

Select TblLogin.*
From TblLogin
Where TblLogin.Username = fOSUserName()

You could also set your global varible to it.

GlobalUsername = fOSUserName()

Although for security concerns, it is probably better to just call it each time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top