By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,560 Members | 1,093 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,560 IT Pros & Developers. It's quick & easy.

Populating a Combo Box with data from a query based on another combo box on same form

100+
P: 119
I have a form with two combo boxes. The first, cboAccount, allows a user to select an account. Ideally, the second combo box, cboSubAccount, will allow the user to select a Sub Account from a list of Sub Accounts for the particular Account already selected in cboAccount.

In the SubAccount combo box 'Row Source' field I have the following query:

SELECT [Sub Accounts].[Sub Account], [Sub Accounts].Account
FROM [Sub Accounts]
WHERE [Sub Accounts].Account=Forms!frmReportFilter1!cboAccount
ORDER BY [Account];

When I load up the form, the behaviour works exactly as I want it to for the first Account I select. However, after that, regardless of which Account I select, the list in the SubAccount combo box corresponds to the first account selected, not each subsequent account selected.

Does anyone know how to modify the query so that the cboSubAccount list always relates to the currently selected cboAccount, not always the first cboAccount?

Thanks.
Nov 30 '06 #1
Share this Question
Share on Google+
2 Replies


100+
P: 119
I figured that the problem was that the query was only being executed once, so I hunted around for a way of executing the query for that control based off an event. I implemented the following code:

Private Sub cboAccount_Change()
cboSubAccount.Requery
cboSubAccount.Value = Null
End Sub


Would be interested to know if anyone has a better solution for what I have been trying to implement, but otherwise I think I'm okay now.
Nov 30 '06 #2

NeoPa
Expert Mod 15k+
P: 31,602
No - because you've got it dead right.
Dec 1 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.