jking.mails
New member
- Local time
- Today, 11:40
- Joined
- Aug 6, 2010
- Messages
- 5
Hello, I am newbie to Access and I use Access 2007. I have 2 tables, tblCategories and tblProducts.
tblCategories is a list of brands.
Each line of tblProducts is a pair of brand and a product of this brand.
Then I created a blank form (formSale) with 2 combo boxes. The first combo box (cboCategories) has Rowsource from tblCategories. I hope the second combo (cboProducts) list the corresponding products when cobCategories is set with a value.
I tried to make the second combo (cboProducts) as a dependent combo or cascading combo by following Microsoft Access 2007 demo, and I wrote cboCategories's AfterUpdate as
Private Sub cboCategories_AfterUpdate()
Me.cboProducts.RowSource = "SELECT tblProducts.ProductName FROM" & _
" tblProducts WHERE tblProducts.Category = '" & Me.cboCategories.Value & "' " & _
"ORDER BY ProductName;"
End Sub
But I just couldn't get the same results.
If I leave the Rowsource of cboProducts empty, as shown in Microsoft's demo, then in my file, no matter which value of cboCategories is chosen, cboProducts is always blank.
If I set the Rowsource of cboProducts as
SELECT ProductName, Category FROM tblProducts WHERE (Category=[forms]![formSale]![cboCategories]);
then I could get the results I want for the first record. However, for the following records, cboProducts always showed the product list of the 1st record and wouldn't refresh, even when the cboCategories box has different values.
What is wrong? I have read many documents but couldn't solve this problem. Please help. Many thanks.
tblCategories is a list of brands.
Each line of tblProducts is a pair of brand and a product of this brand.
Then I created a blank form (formSale) with 2 combo boxes. The first combo box (cboCategories) has Rowsource from tblCategories. I hope the second combo (cboProducts) list the corresponding products when cobCategories is set with a value.
I tried to make the second combo (cboProducts) as a dependent combo or cascading combo by following Microsoft Access 2007 demo, and I wrote cboCategories's AfterUpdate as
Private Sub cboCategories_AfterUpdate()
Me.cboProducts.RowSource = "SELECT tblProducts.ProductName FROM" & _
" tblProducts WHERE tblProducts.Category = '" & Me.cboCategories.Value & "' " & _
"ORDER BY ProductName;"
End Sub
But I just couldn't get the same results.
If I leave the Rowsource of cboProducts empty, as shown in Microsoft's demo, then in my file, no matter which value of cboCategories is chosen, cboProducts is always blank.
If I set the Rowsource of cboProducts as
SELECT ProductName, Category FROM tblProducts WHERE (Category=[forms]![formSale]![cboCategories]);
then I could get the results I want for the first record. However, for the following records, cboProducts always showed the product list of the 1st record and wouldn't refresh, even when the cboCategories box has different values.
What is wrong? I have read many documents but couldn't solve this problem. Please help. Many thanks.
Last edited: