INSERT INTO with WHERE error (1 Viewer)

ECEK

Registered User.
Local time
Today, 01:22
Joined
Dec 19, 2012
Messages
717
Its a syntax error but I'm struggling.
I have a table that I insert a start time ( Now() ) and the text "Full System Update" int the TEXTCONFIRM field.

What I want to do is update the EndTime of that record.
In the meantime I am opening an update query but wondered what is wrong with the code.

Code:
DoCmd.RunSQL ("UPDATE Update_Log SET Update_Log.EndTime = Now(WHERE (((Update_Log.TEXTCONFIRM)='Full System Update'));")

I want to utilise using SQL coding more and wondered if using RunSQL is recommended in VBA ?

Thanks for your thoughts and advice.
 

plog

Banishment Pending
Local time
Yesterday, 19:22
Joined
May 11, 2011
Messages
11,646
SomeFunction(Argument1, Argument2, Argument3)

The above is how functions work. You call it and inside parenthesis you pass it the data it needs. In the above, SomeFunction has 3 arguments; meaning you must pass it 3 different values for it to work.

Now() has no arguments--you are not allowed to pass it anything. So your code incorrectly calls Now().

To use a WHERE clause within an UPDATE statement see this documentation:

https://www.w3schools.com/sql/sql_update.asp

And yes, RunSQL inside VBA is perfectly fine.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 01:22
Joined
Feb 19, 2013
Messages
16,612
Now is a function that does not have parameters. So looks like you are missing a bracket and space

....Update_Log.EndTime = Now() WHERE (((Update....

You can use runsql or you can use .execute. I've never checked to see if one is faster than the other, but with .execute you can return the number of records affected which is useful for error checking and reporting. You can also use it for running queries on disconnected databases (i.e. not linked).
 

ECEK

Registered User.
Local time
Today, 01:22
Joined
Dec 19, 2012
Messages
717
Thanks Guys
I realised that I'd missed the () from Now. It works fine. Thanks for your thoughts and direction.
 

Users who are viewing this thread

Top Bottom