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!

Passing user login from SQL to Access97

Status
Not open for further replies.

DBAchick

Programmer
Apr 27, 2000
61
External Customers use trusted connections through Windows NT to access SQL Server and their user accounts are domain\username which gets them into their own application1.

I have an application2 with an Access97 frontend and a SQL Server 7.0 backend. I want these external customers to log into SQL Server as usual and have an option on their desktop to launch application2. Upon launching it, I need to know who is loggin in within the Access97 frontend of application2. I tried user_name, but it returns Admin because no matter who is logging in, it is going through the Admin account.

I am not going to be able to use Access97 security accounts, this must be seamless to the external customers.

Is there a way to capture the NT/SQL login name and capture it within Access?

Thank you for any suggestions!

DBAChick
 
Open a recordset with the following statement

SELECT @@USERNAME

and that should return the NT login. You may need to make it a pass-through query to retrieve. Also, the variable may actually be called @@USER_NAME. The place I'm currently working in doesn't have SQL Server so I can't check too easily, but hopefully it this should point you in the right direction.
Now that I think of it, you could also use the Environ function which is a VB function that returns various environment variables. Typing Environ("USERNAME") should also return who is currently logged into the PC.
If neither of these worked write back and tell me because I know another more complicated way to get the username (as you may have guessed I've spent a bit of time on this one before). Good Luck. :) Durkin
alandurkin@bigpond.com
 
I think there's also a SQL variable called @@SUSERNAME (or @@SUSER_NAME), I seem to remember using that rather than @@USERNAME for some reason. As I said, they don't have SQL where I am now and I haven't used it in about ten months so I'm a little rusty. Durkin
alandurkin@bigpond.com
 
I got this little piece of code courtesy of The Access Web Forms Index, hope it helps you.

Private Sub Form_BeforeInsert(Cancel As Integer)
Me!UpdatedByUser = Environ("username") ' this is the NT loginID
Me!UpdatedByUser = CurrentUser() ' use this line if you want the Access loginID
Me!UpdatedDate = Date()
End Sub

Umbane
 
I am working with a system where users may have Win 95 or NT PC's on a NT Network. I am trying to query data based on the User's login ID and have it working using the Environ("UserName") capabilities for Win NT users, but not for Win 95 users. I have gotten the network user name using modules, but don't know if I can pass that variable to the query. Any ideas? Thanks a lot!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top