Main Page | Report this Page
Computers Forum Index  »  Computer - Databases - MS Access  »  Updating a table using multi select list box...
Page 1 of 1    

Updating a table using multi select list box...

Author Message
Gordon...
Posted: Mon Oct 26, 2009 7:33 pm
Guest
I'm trying to update a table using as criteria selections made on a
form with a combo box and a multi select listbox (lstproducts). The
combo box part works fine on it's own but when I add the criteria for
the listbox, I get nothing.

I setup the basic update code in the string strSQL then add the
listbox code :

If Me.lstProducts.ItemsSelected.Count > 0 Then
For Each var In Me.lstProducts.ItemsSelected
strProductList = strProductList & Me.lstProducts.Column(0, var) & ",
"
Next
strProductList = Left(strProductList, Len(strProductList) - 2)
strSQL = strSQL & " and [Forms]![frmAssignPostcodes]![lstProducts] In
(" & strProductList & ")"

End If

The code is meant to update those table records where the combo box
criteria is met and where the records contain any one of the (3)
values selected in the multi select list box.

Is my approach wrong?

Gordon
 
Rich P...
Posted: Tue Oct 27, 2009 12:41 am
Guest
Try this: Do a debug.Print strSql

Then copy that debug.print result and paste it into an Access Query Sql
window. If the syntax is correct the query will run from the query
window. If you don't get any resultset then you can start modifying
your where clause (removing args) until you do get a resultset. Once
you get a resultset you can start adding the params you removed back in
one at a time until the query either doesn't return a result - or you
have used up all the params. If when you add the params manually in the
query window - it always returns a resultset - then the problem is in
your coding behind the form.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
 
Gordon...
Posted: Tue Oct 27, 2009 3:08 pm
Guest
On Oct 26, 8:41 pm, Rich P <rpng... at (no spam) aol.com> wrote:
Quote:
Try this:  Do a debug.Print strSql

Then copy that debug.print result and paste it into an Access Query Sql
window.  If the syntax is correct the query will run from the query
window.  If you don't get any resultset then you can start modifying
your where clause (removing args) until you do get a resultset.  Once
you get a resultset you can start adding the params you removed back in
one at a time until the query either doesn't return a result - or you
have used up all the params.  If when you add the params manually in the
query window - it always returns a resultset - then the problem is in
your coding behind the form.

Rich

*** Sent via Developersdexhttp://www.developersdex.com***

HI Rich,

Thanks for the tip which made me think of the problem from a different
perspective - and this allowed me to find the error, which was indeed
on the coding behind my form.

Gordon
 
 
Page 1 of 1    
All times are GMT
The time now is Sat Nov 28, 2009 7:30 pm