CurrentDb.Execute - Syntax

evictme

Registered User.
Local time
Today, 17:39
Joined
May 18, 2011
Messages
168
Trying to update a table with a currentdb.execute UPDATE but I cant figure out the syntax....

Table = [Users], Yes/No Field [Darkmode] , and WHERE field [Users] . THis is what I am trying but does not work:

SQL:
CurrentDb.Execute "UPDATE Users " & _
                  "SET DarkMode = " & 0 & ", " & _
                  "WHERE Users = " & CurrentUser() & ";", _
                  dbFailOnError
 
I do it this way...
Code:
strSQL = "UPDATE Users SET DarkMode=0 WHERE User='" & CurrentUser() & "'"
CurrentDb.Execute strSQL, dbFailOnError
If you get an error, you can use Debug.Print strSQL to see what's wrong.
 
I do it this way...
Code:
strSQL = "UPDATE Users SET DarkMode=0 WHERE User='" & CurrentUser() & "'"
CurrentDb.Execute strSQL, dbFailOnError
If you get an error, you can use Debug.Print strSQL to see what's wrong.
Perfect. Thank you!!!
 
I do it this way...
Code:
strSQL = "UPDATE Users SET DarkMode=0 WHERE User='" & CurrentUser() & "'"
CurrentDb.Execute strSQL, dbFailOnError
If you get an error, you can use Debug.Print strSQL to see what's wrong.
Could I use this code to check it in the On_Load event?

SQL:
DLookup("Darkmode", "Users", "[Users]=" & CurrentUser() & " AND [Darkmode]=" & -1 & "")
 
Could I use this code to check it in the On_Load event?

SQL:
DLookup("Darkmode", "Users", "[Users]=" & CurrentUser() & " AND [Darkmode]=" & -1 & "")
Did you forget the single quotes?
Code:
DLookup("DarkMode", "Users", "[Users]='" & CurrentUser() & "'")
I can't get over it that you use the same name for both the table and a field in it.
 
Did you forget the single quotes?
Code:
DLookup("DarkMode", "Users", "[Users]='" & CurrentUser() & "'")
I can't get over it that you use the same name for both the table and a field in it.
I know 🤦🏻‍♂️. The “Users” table was a local and temporary table that I was using for admin stuff but now some of the features are expanding. Im updating the field names next, i was just wanting to get the code to work and then take care of the cleanup details.

Syntax is my enemy...i always overlook the single quotes but really it just doesnt stick. I need to find a resource where i can learn it completely once and for all.

Thank you for your help. It took me all day trying to get this thing work, on top of other issues.
 

Users who are viewing this thread

Back
Top Bottom