synchronize combos

A

angie

i have pasted the following code in the afterUpdate event of combo1
(Manufacturer) in order to filter the records of combo2 (Part Number) and i
get no data. below is the code:

Private Sub Manufacturer_AfterUpdate()

' Update the row source of the Part_Number combo box
' when the user makes a selection in the Manufacturer
' combo box.
Me.Part_Number.RowSource = "SELECT Part_Number FROM" & _
" Suppliers_tbl WHERE Manufacturer = " &
Me.Manufacturer & _
" ORDER BY Part_Number"

Me.Part_Number = Me.Part_Number.ItemData(0)
End Sub
 
J

Jack Leach

Try requerying the combo after you set it's rowsource...

Me.Part_Number.Rowsource = "blah blah sql"
Me.Part_Number.Requery

hth
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
A

angie

still not working...

i have based my form on a table but the two combos are unbound. they just
facilitate data insertion. could this be the problem?
 
J

Jack Leach

The SQL appears to be correct... that would be the next guess. Is
Manufacturer a text or number value? If it is a number, your sql string is
correct, however if it is a text value you will need to wrap the value with
quotes...

Me.Part_Number.RowSource = "SELECT Part_Number FROM" & _
" Suppliers_tbl WHERE Manufacturer = """ & Me.Manufacturer & _
""" ORDER BY Part_Number"

That's 3 double quotes in a row.. " " "

Aside from that, verify spelling in the SQL string... everything else seems
to be correct, I don't really see a reason it wouln't be working.

hth
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
M

Marshall Barton

Jack Leach said:
Try requerying the combo after you set it's rowsource...

Me.Part_Number.Rowsource = "blah blah sql"
Me.Part_Number.Requery


Since setting the RowSource (and RecordSource) property
automatically loads the object's recordset, a Requery is
never needed in this kind of situation.
 
M

Marshall Barton

angie said:
i have pasted the following code in the afterUpdate event of combo1
(Manufacturer) in order to filter the records of combo2 (Part Number) and i
get no data. below is the code:

Private Sub Manufacturer_AfterUpdate()

' Update the row source of the Part_Number combo box
' when the user makes a selection in the Manufacturer
' combo box.
Me.Part_Number.RowSource = "SELECT Part_Number FROM" & _
" Suppliers_tbl WHERE Manufacturer = " &
Me.Manufacturer & _
" ORDER BY Part_Number"

Me.Part_Number = Me.Part_Number.ItemData(0)
End Sub


As Jack said, I suspect the field type/value may not be what
you think they are.

An alternate way of doing the dependent combo scenario would
be to create a query like:

SELECT Part_Number
FROM Suppliers_tbl
WHERE Manufacturer = Forms!yourform.Manufacturer
ORDER BY Part_Number

Then you can test the query in the query designer and see if
it works or maybe get a better indicator of what's wrong
with it. Just open the form and select something in the
Manufacturer combo box. then opening the query in the
designer will display the list in the dependent combo drop
list. If it doesn't, you can work on the query without
messing around in the form.

When you get the query working, use it as the dependent
combo box's RowSource. The Manufacturer combo box's
AfterUpdate event would be just:
Me.Part_Number.Requery
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top