I've got aa user log for our access database; however, if the system crashes, it does not properly record the user logging out. So I'm trying to create a code to check to see if the user is listed as logged in prior to creating a record.
Here is my code:
Function LogOn()
Dim sUser As String
Dim sSQL As String
DoCmd.SetWarnings False
sUser = Environ("username")
sSQL = "INSERT INTO tblUserLog ( UserID )" _
& "SELECT '" & sUser & "' AS [User] & WHERE tblUserLog.UserID='" & sUser & "' AND tblUserLog.LogOn Is Null & From tblUserLog;"
DoCmd.RunSQL sSQL
DoCmd.SetWarnings True
End Function
I'm getting an error message of
"must have at least one destination table".
I do not get the error message if I remove the WHERE statement.
Thanks for your help. Sorin
FROM
clause is placed at wrong position. Try Updated Query
sSQL = "INSERT INTO tblUserLog ( UserID )" _
& "SELECT '" & sUser & "' AS [User] From tblUserLog WHERE tblUserLog.UserID='" & sUser & "' AND tblUserLog.LogOn Is Null ;"
-----------------^
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.