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

Getting ComboBox recordsource filtered by current data in current record.

P: 2
I have a tabbed subform (data sheet view) for which one of the controls is a combo box. It is based on a query that needs to be filtered by the same field data linking the main and sub forms.

I get a parameter entry box which asks for the value and then retains that value when the parent form records are scrolled thru.

I have created a specific query fort the combobox recordsource and have tried several modifications to the WHERE part of the sql statement with no success.

The query is trying to run before before focus is pointed by mouse to any of the records. How can I have the query run only when the combobox is pulled down?

Any help would be appreciated. I have spent better part of two days searching and trying to figure this out.
Mar 5 '08 #1
Share this Question
Share on Google+
2 Replies


Megalog
Expert 100+
P: 378
First, build a correct sql statement that will work for your rowsource (I wasnt sure if you were having a problem with this part, if so, please post the specific field & form name information you are working with).

Once you have that, then use the 'On Enter' event to set the combo box rowsource.

For example:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboSubformBox_Enter()
  2.  
  3. me.cboSubformBox.rowsource = "<insert rowsource SQL here>"
  4.  
  5. End Sub
and I usually pair that with an 'On Exit' event like such:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboSubformBox_Exit()
  2.  
  3. me.cboSubformBox.rowsource = ""
  4.  
  5. End Sub
So everytime you click that combo box, it's going to requery itself and present you with filtered data off your current criteria. Once this is set, you can delete any code out of the Rowsource property in design view, since it's probably not needed on Load, and will speed things up a bit.
Mar 7 '08 #2

P: 2
Thanks,

I have the first part (i think) but the second is whay I am missing.

I'll try it out an let you know if that works.
Mar 10 '08 #3

Post your reply

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