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!

environ() in RUNSQL command causing glitch

Status
Not open for further replies.

techsupport3977

Technical User
Mar 7, 2005
56
US
Most of my forms use the below RUNSQL command to log what data they are viewing in order for me to serve them better. My concern is the "environ('username')". About 1% of the log table show the user name as blank whne the user has a domain account and is currently logged in the domain. What are the possibilities that can be causing this and how do I fix this? The inability of MsAccess to determine who is logged into the Db also causes a 1% "LOGON FAILURE" to forms because of security rights.

DoCmd.SetWarnings False
DoCmd.RunSQL " INSERT INTO LOG_REPORT ( [DATE], [USER], HOST ,TASK, DB )" & _
"SELECT now() AS [DATE], environ('username') AS [USER], environ('computername') AS HOST ,'" & Me.Name & "','" & CurrentDb.Name & "'"
DoCmd.SetWarnings True
 
CurrentUser returns the UserId logged on the database

But this should work

DoCmd.RunSQL "INSERT INTO LOG_REPORT ( [DATE], [USER], HOST ,TASK, DB )" & _
"Select " & format(Date(), "yyyy-mm-dd") & ", '" & environ("username")& "', '" & environ("computername") & "', '" & Me.Name & "', '" & CurrentDb.Name & "';"

 
You may also try this:
Code:
DoCmd.RunSQL "INSERT INTO LOG_REPORT ([DATE], [USER], HOST ,TASK, DB)" & _
"VALUES (#" & Now() & "#,'" & Environ("username") & "','" & Environ("computername") & "','" & Me.Name & "','" & CurrentDb.Name & "')"


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top