What is wrong with this SQL?

agehoops

Registered User.
Local time
Today, 17:35
Joined
Feb 11, 2006
Messages
351
Code:
DoCmd.RunSQL "INSERT INTO tblAccessLog " _
             & "(DateLoggedOut, TimeLoggedOut) VALUES " _
             & "(#" & Date & "#,#" & Time & "#) WHERE " _
             & "(LogID = '" & LogsID & "');"

Could anyone possibly tell me why this isn't working? Probably something stupid i've done bus still.

When i run it, I am getting the error message "Query input must contain at least one table or query" yet i've told it to use tblAccessLog so i'm just confused.

Thanks
 
A WHERE clause would be valid with a SELECT clause, not a VALUES clause. Are you trying to insert a new record or update an existing one?
 
Update it. I was just a bit lazy, and just copied and modified the script that created it
 
Does that mean you've sorted it out?
 
No. I don't really have that much experience with SQL in honesty. How do I add 2 fields to be updated rather than just the 1?
 
With a comma:

UPDATE TableName
SET Field1 = whatever, Field2 = whatever
WHERE ...
 
ok, i've put
Code:
DoCmd.RunSQL "UPDATE tblAccessLog" & _
             "SET TimeLoggedOut = Time, DateLoggedOut = Date" & _
             "WHERE LogID = LogsID;"

But it's giving me a syntax error. Probably the variables that i'm using are wrong or is it something else?
 
At the very least, you'll need to concatenate in LogsID, as you did in your first post. Date and Time might be okay as they are. Also, pay attention to the spacing when you go to a new line. As you have it, you'll get:

UPDATE tblAccessLogSET ...DateWHERE...

See the problem?
 
Brilliant got it all working now. Thanks for you help, was brilliant :)
 

Users who are viewing this thread

Back
Top Bottom