Username from SQL-server..?

K

Kent J

Hi all,

I have Access form linked to a SQL-table.
The user is logged in to a non-trusted SQL-server database via ODBC. How
can I retrive the SQL-username in Access?
I need the username as parameter to filter the records.

Kent J.
 
B

Baz

Code below. Replace "some_table" with the name of one of your linked
tables.

Dim qry As DAO.QueryDef
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set qry = db.CreateQueryDef("")
qry.Connect = db.TableDefs("some_table").Connect
qry.SQL = "SELECT current_user AS username"
qry.ReturnsRecords = True
Set rs = qry.OpenRecordset
MsgBox rs!username
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top