capturing NT user

  • Thread starter Thread starter alecarnero
  • Start date Start date
A

alecarnero

I m trying to make a log , when the user activate a button automatically
write in field the name of the current user, if this possible??

Thanks Alejandro
 
Dear Alejandro,
You can achieve this by writing code in the OnClick event of the command button.

You can have a text box on the same form as the command button. Set the control source of the text box to the relevant field in your log table. Then enter in the on click event of the command button.

Me.txtCurrentUser = CurrentUser()

HTH
Anand
 
I have one store procedure for this job:

create proc userNT as
-- declaramos las variables
declare @name varchar(30), @lenindex int, @lenall int, @nomeuser varchar(10)
-- devuelve el nombre de usuario que entro
select @name= suser_sname()
select @lenall = len(@name)
select @lenindex = CHARINDEX('\',@name)
-- limpiamos las variables y tenemos el nombre
select substring (@name, @lenindex+1,@lenall-@lenindex) as ntusername
return

thos works but i dont know how to asign this to a control , i have try this
but not work

Private Sub user1_Click()
Dim pum, sql As String

sql = "exec usernt"

pum=DoCmd.RunSQL sql
End Sub
what is wron in this code???

Anand said:
Dear Alejandro,
You can achieve this by writing code in the OnClick event of the command button.

You can have a text box on the same form as the command button. Set the
control source of the text box to the relevant field in your log table.
Then enter in the on click event of the command button.
 
At best, using RunSQL lets you execute the stored procedure, but doesn't
give you any way of retrieving values from it.

Your stored procedure is actually going to return a recordset. However, you
need to establish a connection to SQL Server to be able to run it. Your best
bet would be to create a pass-through query that runs the stored procedure,
and to open a recordset based on that query.
 
I have resolve with this code :

ALTER procedure "operador" as

insert control (usuario)
exec ('select suser_sname()')

without a recordset, thanks by your help
 
Back
Top