473,382 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Filter a Combo box on a multi row form

I have a form which loads a recordset.
Within each row I want a combo box which is loaded by values from another table filtered by a value from a column on that row.

I have set the Row Source of the combo box to
Expand|Select|Wrap|Line Numbers
  1. SELECT tblTempVIC.icID, tblTempVIC.description FROM tblTempVIC WHERE (((tblTempVIC.part_id)=Forms!frmPartInput1!Part_id)) ;
expecting it to pull the Part_id from the current row.
However, every combo box is filtered by the value of the first row.
Mar 27 '08 #1
2 1743
PianoMan64
374 Expert 256MB
I have a form which loads a recordset.
Within each row I want a combo box which is loaded by values from another table filtered by a value from a column on that row.

I have set the Row Source of the combo box to
Expand|Select|Wrap|Line Numbers
  1. SELECT tblTempVIC.icID, tblTempVIC.description FROM tblTempVIC WHERE (((tblTempVIC.part_id)=Forms!frmPartInput1!Part_id)) ;
expecting it to pull the Part_id from the current row.
However, every combo box is filtered by the value of the first row.
Because you have to base it on what is currently on the form, and not what the bound control on the form is currently pointing too.

It may look like you're doing that already, but the problem comes in because you reference the bound Record value of the control and not what the value on the form that you're editing. It may be different because you're making changes to create a new record.

If you set the .RowSource in VBA just simple replace the Forms!frm..... with me.part_id

example:

Expand|Select|Wrap|Line Numbers
  1. me.ComboBoxControlname.RowSource = "SELECT tblTempVIC.icID, tblTempVIC.description FROM tblTempVIC WHERE (((tblTempVIC.part_id)=" & me.part_ID & "));"
  2.  
If you're simply setting that in the Combobox control itself, you're going to need to set that in code so it knows how to populate.

So on the previous control before it gets to the combo box, you need to include the following code section:

Expand|Select|Wrap|Line Numbers
  1.  
  2.      me.comboboxcontrolname.RowSource = "SELECT tbTempVIC.icID, tblTempVIC.Description FROM tblTempVIC WHERE tblTempVIC.Part_ID=" & me.Part_ID
  3.      me.comboboxcontrolname.requery
  4.  
You'll put that on the event property of onLostFocus.

Hope that helps,

Joe P.

If you need more detailed answer to this, please let me know.
Mar 29 '08 #2
Because you have to base it on what is currently on the form, and not what the bound control on the form is currently pointing too.

It may look like you're doing that already, but the problem comes in because you reference the bound Record value of the control and not what the value on the form that you're editing. It may be different because you're making changes to create a new record.

If you set the .RowSource in VBA just simple replace the Forms!frm..... with me.part_id

example:

Expand|Select|Wrap|Line Numbers
  1. me.ComboBoxControlname.RowSource = "SELECT tblTempVIC.icID, tblTempVIC.description FROM tblTempVIC WHERE (((tblTempVIC.part_id)=" & me.part_ID & "));"
  2.  
If you're simply setting that in the Combobox control itself, you're going to need to set that in code so it knows how to populate.

So on the previous control before it gets to the combo box, you need to include the following code section:

Expand|Select|Wrap|Line Numbers
  1.  
  2.      me.comboboxcontrolname.RowSource = "SELECT tbTempVIC.icID, tblTempVIC.Description FROM tblTempVIC WHERE tblTempVIC.Part_ID=" & me.Part_ID
  3.      me.comboboxcontrolname.requery
  4.  
You'll put that on the event property of onLostFocus.

Hope that helps,

Joe P.

If you need more detailed answer to this, please let me know.

Thanks for the reply.

That works and I now understand what's happening!
Apr 1 '08 #3

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

Similar topics

3
by: Richard | last post by:
Hi, I have a form based on a table. When I filter the form I want to run a report based on the same table with the same filter as the form. No problem until I want to filter a combo box where...
8
by: dick | last post by:
I am just trying to print/report the results of a "filter by selection" which is done by right-clicking a form, filling in values, and "applying the filter." I have searched the newsgroups, and...
2
by: cefrancke | last post by:
I have a form (no underlying record set) that has two separate sub-forms on it. Each sub-form has data from two different tables. Above each sub-form there is one unbound combo box with a SQL...
3
by: Stewart | last post by:
Hi all! My (relatively small) database holds data on staff members and the projects (services) that they are assigned to. In my form frmStaff, I have a list of staff members - it is a...
6
by: bammo | last post by:
MS Access 2003, Windows XP SP2, VBA I have a continuous form that allows edits and filters, but not deletions or additions. I filter the form based on combining selections the user makes in...
2
by: patriciashoe | last post by:
Greeting All I have several public variables which I use to build a filter string that I would like to use when I open a form and several associated sub forms. I have set the value of the combo...
1
by: woodey2002 | last post by:
Hi Everyone and many thanks for your time.. I am trying to begin access and a bit of VBA i am enjoying it but I have a annoying problem I just can’t get any where on. My databse mostly includes...
2
by: sap01 | last post by:
Hi All, I want to display the data from a table by applying filter in the form. I want three combo box filter in the form. If I select all the three then it should display the data in the form from...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.