ListBox Query Question

  • Thread starter Thread starter Stephen
  • Start date Start date
S

Stephen

I've got 2 unbound listboxes on a form.

CUSTOMERS...which lists all active customers from the
Customers Table
PRODUCTS...which lists all products from the Products
Table
I also have 1 unbound Textbox named ADJUSTSELLBY

I want to create an update query that will take the
selected PRODUCTS for the selected CUSTOMERS and change
the sellprice by the ADJUSTSELLBY.

I don't know how to get my Update Query to recognize that
I want to use the Selected items on this form.

Any help would be appreciated.

Thanks

Stephen
 
Hi,
You are going to need to code a solution for this.
You can't directly refer to a multi-select listbox from a query.

I'll give you sample code for a simple select statement and you can build from there.
Basically you need to loop through the Selected Items and build a comma delimited list
which will be your IN clause in the query.

So... **untested**

Dim varItem As Variant
Dim strSql As String
Dim strIn As String

strSql = "Select * From Wherever Where custid IN ("

'build list
For Each varItem In Me.yourListbox.ItemsSelected
strIn = strIn & varItem & ","
Next varItem

'remove trailing comma
strIn = Left(strIn,Len(strIn) -1)

strSql = strSql & strIn & ")"

now you have a sql statement that you can execute
 
Back
Top