Trouble with SQL Update Query using AutoNumber field (1 Viewer)

brewpedals

Registered User.
Local time
Today, 11:52
Joined
Oct 16, 2002
Messages
32
I have a table nameed Users whose Primary Key is a AutoNumber field named UserID and a boolean field named LoggedIn4 that tracks wheter the user is logged in to the application.

I want to log the user off when they exit the application using the following code, but I either get a data type error, or it fails to execute the SQL Statement.

I have tried:
- Declaring strUserID as String, Integer, Long and Double
- Useing the following syntax for the criteria in the SQL
'" & strUSerID & "'
'strUserID'
' & strUserID & '
- Originally, I used DoCmd.OpenQuery to call a query definition, but it ocationally failed to find the value in Forms!DetectIdleTime.UserID.Value. This is a form where I store the user id in an unbound control. Should I be storing it in a global variable? How?


Any help is appreciated. :confused:

Code:
Dim strSQL As String
Dim strUserID As Integer

strUserID = Forms!DetectIdleTime.UserID.Value

strSQL = "UPDATE Users SET Users.LoggedIn4 = 0 " & _
         "WHERE Users.ID= 'strUserID'"

DoCmd.RunSQL strSQL
 
Last edited:

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:52
Joined
Aug 30, 2003
Messages
36,140
Try this if Users.ID is a text field in the table:

"WHERE Users.ID= '" & strUserID & "'"

or this if it's numeric:

"WHERE Users.ID= " & strUserID
 

brewpedals

Registered User.
Local time
Today, 11:52
Joined
Oct 16, 2002
Messages
32
It is numeric so your example

"WHERE Users.ID= " & strUserID

worked like a champ.

Many Thanks! :)
 

Users who are viewing this thread

Top Bottom