List Box data to Update Table

IanT

Registered User.
Local time
Today, 18:41
Joined
Nov 30, 2001
Messages
191
Hi

I am trying to update a table with data selected from a list box, I have tried the code below with out success, can any one help.

Thanks in advance...........


Dim strCriteria As String
Dim varItem As Variant
Dim strSQL As String

For Each varItem In Me!lsthold.ItemsSelected
strCriteria = strCriteria & ",'" & Me!lsthold.ItemData(varItem) & "'"
Next varItem

DoCmd.RunSQL "INSERT INTO tblQuote ([Product_Code],[Description]) VALUES (Criteria);"
 
The INSERT you are using requires 2 values (and only 2) for each running.
Your criteria can only contain 'VALUE1','VALUE2'
for the INSERT to work properly.
I would guess you would have to put your INSERT inside your loop, and pull each string pair out and supply it to the INSERT there.
 
Easier than code it the GUI way.
I assume that the values in your list box are known or you would just use a text box, so.....
Create a table that contains the know values.
Bind the list box to the table and column you want to populate.
Set the Row Source Type to Table/Query
In Row Source create a query that get the values from the table that has the know values.
All done!
You can make it so if a new value has to be added to the list you can make a "On Double Click" event procedure that will open a form in add mode.
 

Users who are viewing this thread

Back
Top Bottom