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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trap CLIENTNAME 1

Status
Not open for further replies.

BernieH

Programmer
Feb 2, 2006
3
US
I have a multiuser database in a terminal server environment. Using code I found at various help sites, I trap username, and machinename at logon. However, the machinename is the server's name, so I also need to find the CLIENTNAME. I'm still learning, and would appreciate any help.

 
Here is a function where I am doing what I think you are talking about it was created by modifying other posts on this website - thanks to all who contributed:

Function LogError()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim ctlCurrentControl As Control
Dim strControlName As String
Dim strFormName As String
Dim varTerminalId As Variant
Dim varDbUser As Variant
Dim varNetUser As Variant

Set db = CurrentDb
Set rst = db.OpenRecordset("tbl ErrorLog")

'get computer environment
varTerminalId = fOSMachineName()
varTerminalId = Left(varTerminalId, 35) 'avoid error if field too large to write to table

varNetUser = fOSUserName()
varNetUser = Left(varNetUser, 35) 'avoid error if field too large to write to table

Set ctlCurrentControl = Screen.ActiveControl
strControlName = ctlCurrentControl.Name

strFormName = "frm User Sign In"

If isOpen(strFormName) Then
If IsNull(Forms![frm User Sign In]![cmbUser]) Then
'not signed in
varDbUser = "Not signed in"
Else
varDbUser = DLookup("[EmpLast]", "tbl Employees", "[EmpID]= Forms![frm User Sign In]![cmbUser]") & ", " & DLookup("[EmpFirst]", "tbl Employees", "[EmpID]= Forms![frm User Sign In]![cmbUser]")
End If
Else
varDbUser = "User Sign In Form not Open"
End If

rst.AddNew
rst.Fields("TimeDateStamp") = Now 'Timestamp
rst.Fields("Date") = Date 'ShortDate for GroupBy in queries and sorting
rst.Fields("ErrorNumber") = Err.Number
rst.Fields("ErrorDescription") = Err.Description
rst.Fields("FormName") = Screen.ActiveForm.FormName
rst.Fields("ControlName") = strControlName
rst.Fields("TerminalID") = varTerminalId
rst.Fields("dbUserName") = varDbUser
rst.Fields("NetworkUserName") = varNetUser
rst.Update

rst.Close
Set rst = Nothing
Set db = Nothing

End Function
 
Thanks evalesthy for the reply.
I am already using the fOSMachineName() and fOSUserName().
However, on the terminal server, the fOSMachineName()
returns the name of the server. I need to know which machine the user was logged onto at the time. This is shown as the CLIENTNAME in the environment setting. I am looking for a way to retrieve this CLIENTNAME.

Thanks again,
BernieH
 
Have you tried Environ("CLIENTNAME") ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV - yes I tried that, but it did not return anything in the terminal server database.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top