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

HOW TO CAPTURE USER ID AND USE IT IN QURTY.

Status
Not open for further replies.

emma113

Programmer
Nov 30, 2001
8
US
I would like to be able to capture user ID and then use it in a select query (ACCESS) to filter data for just that user? i.e. select all records from a table for sales agent John. This application has many users retrieving data at the same time.
 
Declare the following api call in a module -

Public Declare Function getUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

- and then add a function like this -

Public Function getUser() As String
'Generic function to return the NT user name
'Used for security requirements
Dim strBuffer As String * 255
Dim lngLength As Long
Dim lngI As Integer

strBuffer = Space(255)
lngI = getUserName(strBuffer, 255)
getUser = Mid(strBuffer, 1, (InStr(1, strBuffer, Chr(0)) - 1))
'This line to cut out any null strings that may appear at the end
End Function

When you call this function your code, it will return the logged users sign on. There is also a getUserID api but it appears to call the exact same function.

Brendan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top