Insert into table using VB

chris-uk-lad

Registered User.
Local time
Today, 14:13
Joined
Jul 8, 2008
Messages
271
Hi all,

Im trying to insert a vlue into a table where the corresponding cell in another column = 'LIVE'

Code:
ObjConn.Execute "INSERT INTO tblRESULTS (REF) VALUES '" & strREF & "' WHERE (ACTION) = 'LIVE'"

Whats wrong with my syntax? Thanks
 
I'm confused by "where the corresponding cell in another column = 'LIVE'". Since you're inserting a new record, existing records are irrelevant. Do you really want to modify an existing record? Your syntax is wrong because a VALUES clause wouldn't have a WHERE clause. You could use the SELECT clause which would allow it.
 
I'm confused by "where the corresponding cell in another column = 'LIVE'". Since you're inserting a new record, existing records are irrelevant. Do you really want to modify an existing record? Your syntax is wrong because a VALUES clause wouldn't have a WHERE clause. You could use the SELECT clause which would allow it.


I currently have
Code:
ObjConn.Execute "INSERT INTO tblRESULTS (REF) VALUES (" & strREF & ")"

Which works fine for adding a value to a single column on a blank table.

What i need is to update my table in a cell in column REF where column ACTION has a cell that shows its value as LIVE

So, in sql:

Code:
update tblRESULTS set REF = '001' where ACTION = 'LIVE'

But i need this in VB for an Access Table. The REF is a unique ID
 
Well, you basically did it correctly but used the wrong query. You want the UPDATE query, not the INSERT query.
 
Could you show me the basic layout of the update statement? ive tried it with the SQL sequence but doesnt work for me :(
 
You already have the layout:

update tblRESULTS set REF = '001' where ACTION = 'LIVE'

so

ObjConn.Execute "update tblRESULTS set REF = '" & strREF & "' where ACTION = 'LIVE'"
 

Users who are viewing this thread

Back
Top Bottom