Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query using listbox value

Status
Not open for further replies.

lopster10

Technical User
Jan 26, 2009
17
DE

Hi Guys,

Im new to SQL and am trying to use the value from a list box to then use in a query.

I am using the following syntax:

DoCmd.RunSQL ("INSERT INTO tableName (fieldName) VALUES ('value') WHERE tableName.fieldname = ('" & listvalue "'); )

So basically in the list box they are selecting a value, this value is then looked up in the table and a value is added to one of this records fields.

When I run this I get an error relating to the semi-colon, but Ive tried various other ways all of which havent been sucessful.

Can anyone please tell me where im going wrong?

Regards
 
Sorry I meant to write: ('" & listvalue & "');
 
DoCmd.RunSQL "INSERT INTO tableName (fieldName) VALUES ('value') WHERE fieldname='" & listvalue & "'"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

I am confused here (it does not take much... :) )

Are you trying to INSERT a new record into your tableName, or are you trying to UPDATE a field in your table?

[tt]INSERT INTO tablename VALUE ‘abc’ WHERE FieldX = ‘xyz’[/tt]

does not make much sense to me…..


Have fun.

---- Andy
 
Oops, didn't realize that !
Code:
DoCmd.RunSQL "UPDATE tableName SET fieldName='value' WHERE fieldname='" & listvalue & "'"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi Guys,

Yeah after taking a further look into it I also realised it didnt actually make sense. But PHV your example worked perfectly, thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top