In addition to the good advice you have received from others, you can do it
by creating a stored procedure in SQL Server and calling the stored
procedure from Access using ADO. I'm not suggesting this method is
necesarily any better than using a pass-through query. I just happened to
have code to do this in a non-Access app and was able to quickly convert it
to work with Access ...
First, create a stored procedure in SQL Server ...
CREATE PROCEDURE [dbo].[SystemUser_Select] AS SELECT SYSTEM_USER
Now we need to call that stored procedure from Access ...
Public Function GetSqlName() As String
Const ConnectionString As String = "Provider=SQLOLEDB.1;" & _
"Integrated Security=SSPI;Persist Security Info=False;" & _
"Initial Catalog=YourDatabaseHere;Data Source=(local)"
Dim cn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Set cn = New ADODB.Connection
cn.ConnectionString = ConnectionString
cn.Open
Set cmd = New ADODB.Command
With cmd
Set .ActiveConnection = cn
.CommandText = "SystemUser_Select"
.CommandType = adCmdStoredProc
End With
Set rst = cmd.Execute
GetSqlName = rst.Fields(0).Value
cn.Close
End Function
--
Brendan Reynolds
Access MVP
Me said:
Doug,
Your suggestion to use the sql
select user, ...
to get the sql login name doesn't work in Access, please look at the
advapi32.dll thread and reply.
Thank you,
-Me