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.
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.