473,414 Members | 1,609 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,414 software developers and data experts.

Filtering a list box using a variable?

2
Hi, To put it simply I need to filter information in a list box according to a particular field in a table.

I have tables "Table1" and "Table2". Table1 contains primary key "Key1", this is a foreign key in Table2.

At the moment I have used the following code to show all the records in Table2 in a list box (name List_Box1):

List_Box1.rowsource = "SELECT [Table2].[ID],[Table2].[Information],[Table2].[Date],[Table2].[Key1] FROM [Table2] ORDER BY [Date];"

In a previous form the user has selected a record in Table1, the value of Key1 (an identifying integer) is stored in a global variable called "Selected_ID"

I want List_Box1 to be filtered so that the only records from Table2 that appear have the same Key1 as Selected_ID. Thanks
Jul 1 '08 #1
4 1987
Stewart Ross
2,545 Expert Mod 2GB
All you need is a WHERE clause on your existing row source code:
Expand|Select|Wrap|Line Numbers
  1. List_Box1.rowsource = "SELECT [Table2].[ID],[Table2].[Information],[Table2].[Date],[Table2].[Key1] FROM [Table2] WHERE [Table2].[Key1] = " & Selected_ID & " ORDER BY [Date];"
-Stewart
Jul 1 '08 #2
Lobius
2
Excellent! It works thanks a lot, i've been playing around with applyfilter and things for hours with no progress.
Jul 1 '08 #3
NeoPa
32,556 Expert Mod 16PB
You will need to ensure that the SQL for the ListBox is updated any time the global variable changes of course.
Jul 2 '08 #4
NeoPa
32,556 Expert Mod 16PB
We get so many questions in here from people trying to do things completely the wrong way around. It's nice to get one from someone who's having trouble because they are thinking the RIGHT way, but Access decided to do things differently (It doesn't supprt filtering for form controls - just for forms & reports).
Jul 2 '08 #5

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

Similar topics

1
by: N.K. | last post by:
Hello, I'm trying to find a way to flexibly filter a column in a row of data read from a file. I will have data type of that column, the operation to be performed on it (like >, <, <= etc.) and the...
0
by: William Park | last post by:
1. Here is shell version of Python filter() for array. Essentially, you apply a command on each array element, and extract only those elements which it returns success (0). This is specialized...
3
by: Alex Ayzin | last post by:
Hi, I have a problem that might be easy to solve(possibly, I've just overlooked an easy solution). Here we go: I have a dataset with 2 datatables in it. Now, I need to do the following: if...
13
by: kevinold | last post by:
Hello everyone, I have a list of about 1600 employees that I'd like to have displayed in a form. I'd like to make the "search" for the user as easy as possible. I ran across this:...
19
by: William Wisnieski | last post by:
Hello Everyone, I have a main form with a datasheet subform that I use to query by form. After the user selects two criteria on the main form and clicks the cmdShowResults button on the main...
5
by: sensible | last post by:
Can I solve this problem using Access? If so, will some give this newbie a simple step by step on how to go about it, please....all the way from File/New. In Excel I am using...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
2
by: JUAN ERNESTO FLORES BELTRAN | last post by:
Hi you all, I am developping a python application which connects to a database (postresql) and displays the query results on a treeview. In adittion to displaying the info i do need to implement...
3
by: Harry Haller | last post by:
Hello, I want to implement a generic list which will be used to display 7 columns in a GridView. One should be able to sort, filter and page each of the 7 columns. Ideally the filter should be...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.