CurrentUser() returning "Admin" for all Users?

  • Thread starter Thread starter HumanJHawkins
  • Start date Start date
H

HumanJHawkins

I have made a VB funtion for the "On Lost Focus" event of a text box. The
code is this:

Private Sub CABApprovedDate_LostFocus()
If IsNull(CABApprovedDate.Value) Then
CABApprovedBy = ""
Else
CABApprovedBy = CurrentUser()
End If
End Sub


It is supposed to put the username of the current user into another field.
However, no matter who logs in, it always puts "Admin" into the box.

Two problems:
1. I have verified that these users are not admins... They have only
public access and no server roles, ownership, etc.

2. Even if they were admins, this would be a problem, as I want their
username to be entered... It does me no good unless I know who made the
entry.

Thanks in advance for any help.
 
Hi,

If your using Integrated Windows Authentication, then you could try using:

Currentproject.Connection("User id") instead of Currentuser()

HTH,

Martin.
 
On an Access frontend you can use the Environ("UserName") function to
return the Windows NT Logon.
 
<CUT>you could try using:
Currentproject.Connection("User id") instead of Currentuser()

I found that it would be pretty easy to parse the username out of
Currentproject.Connection.ConnectionString, whether you are using Windows
Authentication or not.

Thanks for sending me in the right direction!
 
HumanJHawkins said:
<CUT>

Thanks. This is the best solution yet. It works well regardless of
authentication type.

Dohh! I didn't realize it since my windows and SQL logins are the same, but
this does in fact only work properly (as you said) is using WIndows
authentication... It returns the Windows login regardless of how you are
logged into SQL.

I think the better universal solution (or perhaps SQL authentication only
solution) is to parse it out of the
"Currentproject.Connection.ConnectionString" string.

I plan to just find the first case of ";User ID=", then capture everything
between that and the next semicolon.

Cheers!
 
I'm sorry the correct syntax is:

currentproject.connection.properties("User ID")

This will parse out the user id for you.

HTH,

Martin.
 
As Martin said, the easiest way is probably just to look at the
..Properties("User ID") value, but if you want more control for some reason,
or if you're using Integrated Authentication (SSPI), you can also use a SQL
statement to use one of SQL Server's functions instead.

For example, you might want to use
SELECT susr_sname() AS UserName
or
SELECT usr_name() AS UserName

then just pull out the UserName value from whichever statement works for
you.

There are a few other varieties of the usr_name function...look in SQL
Server help for all the various details of each one.




Rob
 
Back
Top