currentUser() & Jet SQL

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

Hi everyone,

I'm writing some software that uses an Access (2002) database as the
backend. I have user-level security implemented. I would like to track
who's done what to the DB using the currentUser() function in a stored
query. Only problem is this works fine when logging in through Access, but
not from the app (Uses Jet 4.0 and ADO.NET to access DB). Any ideas -
short of manually sending the user's name from the app?

Thanks,

Dave Hagedorn
 
When you're connecting to a Jet database from outside of Access, you're
strictly going through the Jet Engine, which doesn't know about most
functions. In other words, manually sending the user's name from the app is,
AFAIK, the only option.
 
You could get the network userid of the person. I picked
up this code(note the copyright notice) written by Dev
Ashish. I have not tried it. Good luck

Jim


API: Get Login name userId


(Q) How do I retrieve the UserName with which the user is
logged into the network?
(A) Paste the following code in a new module and call the
function fOSUserName.
'******************** 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 **************************
 
Back
Top