473,382 Members | 1,749 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.

How to limit values in a list box based on selection from a combo box?

Hi, I'm trying to create a form (MS Access 2003) that currently has 2 items in it: a combo box and a list box. I'd like to be able to make a selection from the combo box and have the list box display a filtered version of the data based on the selection from the combo box.

For example, the combo box has a list of different projects, (a, b, c, and d) and the list box has a list of ALL of the reports associated with all of the projects. I'd like to be able to select project "a" from the combo box and get ONLY the reports associated with project "a" displayed in the list box. The list box is currently based on a query that contains 2 columns, a column with the "report name" (which will remain VISIBLE) and a 2nd column (which will eventually become not visible) with the "report type" (the "report type" here should match up with the project selected from the combo box).

Any suggestions would be greatly appreciated!
Attached Images
File Type: jpg ReportPic.jpg (44.5 KB, 801 views)
Mar 24 '11 #1

✓ answered by ADezii

First, a couple of Assumptions:
  1. Table name is tblReports with the following Fields:
    1. [Report Name] {TEXT}
    2. [Report Type] {TEXT}
  2. Combo Box is named cboProjects and contains only the Unique Report Types that exist in tblReports, namely:
    1. NCAR
    2. OFI
    3. QI
    4. TIR
    5. etc...
  3. List Box is named lstReports, and has the following characteristics:
    1. Row Source Type = Table/Query
    2. NO Row Source defined
    3. Column Count = 1
    4. Bound Column = 1
    5. Column Width = Width of widest Report Name
  4. In the AfterUpdate() Event of cboProjects, Copy-N-Paste the following Code:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub cboProjects_AfterUpdate()
    2. If IsNull(Me![cboProjects]) Then Exit Sub
    3.  
    4. 'Do any Reports exist for the selected projected?
    5. If DCount("*", "tblReports", "[Report Type] = '" & Me![cboProjects] & "'") = 0 Then
    6.   Me![lstReports].RowSource = ""
    7.     MsgBox "No Reports exist for Project [" & Me![cboProjects] & "]", vbExclamation, "Report(s) Not Found"
    8.       Exit Sub
    9. End If
    10.  
    11. 'If you get here, you have 1 or more Reports for the selected Project
    12. Me![lstReports].RowSource = "SELECT [Report Name] FROM tblReports WHERE [Report Type] = '" & Me![cboProjects] & "' " & _
    13.                             "ORDER BY [Report Name];"
    14. End Sub
  5. Any questions, feel free to ask.

3 5287
ADezii
8,834 Expert 8TB
First, a couple of Assumptions:
  1. Table name is tblReports with the following Fields:
    1. [Report Name] {TEXT}
    2. [Report Type] {TEXT}
  2. Combo Box is named cboProjects and contains only the Unique Report Types that exist in tblReports, namely:
    1. NCAR
    2. OFI
    3. QI
    4. TIR
    5. etc...
  3. List Box is named lstReports, and has the following characteristics:
    1. Row Source Type = Table/Query
    2. NO Row Source defined
    3. Column Count = 1
    4. Bound Column = 1
    5. Column Width = Width of widest Report Name
  4. In the AfterUpdate() Event of cboProjects, Copy-N-Paste the following Code:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub cboProjects_AfterUpdate()
    2. If IsNull(Me![cboProjects]) Then Exit Sub
    3.  
    4. 'Do any Reports exist for the selected projected?
    5. If DCount("*", "tblReports", "[Report Type] = '" & Me![cboProjects] & "'") = 0 Then
    6.   Me![lstReports].RowSource = ""
    7.     MsgBox "No Reports exist for Project [" & Me![cboProjects] & "]", vbExclamation, "Report(s) Not Found"
    8.       Exit Sub
    9. End If
    10.  
    11. 'If you get here, you have 1 or more Reports for the selected Project
    12. Me![lstReports].RowSource = "SELECT [Report Name] FROM tblReports WHERE [Report Type] = '" & Me![cboProjects] & "' " & _
    13.                             "ORDER BY [Report Name];"
    14. End Sub
  5. Any questions, feel free to ask.
Mar 24 '11 #2
Works like a charm! Thank you very much!
Mar 24 '11 #3
ADezii
8,834 Expert 8TB
You are quite welcome, Lori, glad to be able to help.
Mar 24 '11 #4

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

Similar topics

3
by: CJM | last post by:
Not sure if this is entirely on-topic.... I would ideally like to present an initial list based on one DB table. The user selects an item, and the 2nd list is updated to show items from the DB...
18
by: booner | last post by:
I have a form that when it loads I would like to highlight the values (from a DB) that have been selected in a multiple selection list (<select multiple="true">. function onLoad() {...
2
by: Jeff | last post by:
Hello All: What I am trying to do is bind a textbox (really several text boxes) based on a list box selection. Basically what I'm dealing with are two tables with a 1 to 1 relationship. I...
2
by: Max | last post by:
Have a DropDownListBox where I want to give users the option to select one of the values, but allow them to enter a freeform text value if they choose to do so in lieu of the proffered values. Kind...
4
by: Rabbit | last post by:
Hi, I've been using MS Access to devleop applications for long time, I like a feature called "Limit To List" when setting combo box in design time (accept text only when matches one of the...
1
by: injanib via AccessMonster.com | last post by:
is it possible that if the limit to list property of a combobox is set to true the focus is passed onto another field? What I mean is that I have a combo box with the limit to list property set to...
1
kcdoell
by: kcdoell | last post by:
Hello: I have a table called "Products". In there are two fields; "Product Name" & "Product Category". I have about 24 products but only 3 product categories (for example Product Category A, B,...
4
by: Mtek | last post by:
Hi, We have a combo box on our page, which gets populated via a MySQL Query in PHP. What we want to do is to print the values on the page in a table that correspond the to selection from the...
6
by: troy_lee | last post by:
I have a continuous form that has one combo box (cbo1) with the selectable values of "Removal" and "Installation". I would like to change another combo box (cbo2) value list based on the selection...
20
by: Daniel Yantis | last post by:
Combo Box 1 Displays a query/list with 2 columns: SELECT Classes.CLASS_DESC, Judges.Judge, * FROM Classes; Combo Box 2 Displays a query/list: SELECT Judges.Judge FROM Judges; I want...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: 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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.