473,494 Members | 2,223 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Filter a Drop down from a drop down box

6 New Member
Hey all, I am looking for help on creating a after update to filter another drop down box. I am looking to have a drop down box based on a table and from this drop down box filter another drop down box based on a seperate table.


Thank You.


Access 2003
Windows XP
Apr 29 '08 #1
4 3533
questionit
553 Contributor
Hey all, I am looking for help on creating a after update to filter another drop down box. I am looking to have a drop down box based on a table and from this drop down box filter another drop down box based on a seperate table.


Thank You.

Access 2003
Windows XP
Hi

It is very easy to do.

You can have write sql statement that will query the table and you can

use the result of sql to filter another drop-down menu.

In Access, you can set source for drop-down menus.
To get what you are trying to do - you can set a default sql for your drop-down menu(s). And when you select an item in one of your drop-down menu, execute your sql to update/filter source of the other drop-down menu.

Hope it helps.

Qi
Apr 29 '08 #2
nathanh
6 New Member
Hi

It is very easy to do.

You can have write sql statement that will query the table and you can

use the result of sql to filter another drop-down menu.

In Access, you can set source for drop-down menus.
To get what you are trying to do - you can set a default sql for your drop-down menu(s). And when you select an item in one of your drop-down menu, execute your sql to update/filter source of the other drop-down menu.

Hope it helps.

Qi

Hey Qi, is there any chance that you could post a example for me.

Thank You.
Apr 30 '08 #3
questionit
553 Contributor
Hey Qi, is there any chance that you could post a example for me.

Thank You.

This is an example :

1- Create 2 Combo-Boxes (Say Combo1 and Combo2)

2- Set default values of your both Drop-down menus by setting Row Source of your drop-down menus in the property box, seperately e.g: SELECT amount FROM table1 WHERE amount > 1000.

Note: It is not neccessary to set default values of drop-down menus using sql, you can also write a value list instead.

You can set Row Source of each drop-down menu similarly with any sql query.

Now you want to update/filter Combo2 on selecting a value in Combo1.

3- Write simple code
Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo1_BeforeUpdate(Cancel As Integer)
  2. Dim sql As String
  3.  
  4. If Me.Combo1.Value = "April" Then
  5.   sql = "SELECT Table1.amount FROM Table1 WHERE (((Table1.amount)<100));"
  6.  
  7. Else If Me.Combo1.Value = "March" Then
  8.    sql = "SELECT Table1.amount FROM Table1 WHERE Table1.amount)>100));"
  9. End If
  10.  
  11. // here you filter your other Drop-down menu by changing its Row Source using sql
  12.    Me.Combo2.RowSource = sql
  13.  
  14.  
Hope it helps
Qi
Apr 30 '08 #4
nathanh
6 New Member
This is an example :

1- Create 2 Combo-Boxes (Say Combo1 and Combo2)

2- Set default values of your both Drop-down menus by setting Row Source of your drop-down menus in the property box, seperately e.g: SELECT amount FROM table1 WHERE amount > 1000.

Note: It is not neccessary to set default values of drop-down menus using sql, you can also write a value list instead.

You can set Row Source of each drop-down menu similarly with any sql query.

Now you want to update/filter Combo2 on selecting a value in Combo1.

3- Write simple code
Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo1_BeforeUpdate(Cancel As Integer)
  2. Dim sql As String
  3.  
  4. If Me.Combo1.Value = "April" Then
  5.   sql = "SELECT Table1.amount FROM Table1 WHERE (((Table1.amount)<100));"
  6.  
  7. Else If Me.Combo1.Value = "March" Then
  8.    sql = "SELECT Table1.amount FROM Table1 WHERE Table1.amount)>100));"
  9. End If
  10.  
  11. // here you filter your other Drop-down menu by changing its Row Source using sql
  12.    Me.Combo2.RowSource = sql
  13.  
  14.  
Hope it helps
Qi
here is what i came up with from you example but it is giving me a error. Thank you.

Private Sub TYPE_BeforeUpdate(Cancel As Integer)
Dim sql As String

If Me.TYPE.Value = "MISCONDUCT" Then
sql = "SELECT STATDISCRP.MISCONDUCT FROM STATDISCRP;"

Else If Me.TYPE.Value = "TRANSITION" Then
sql = "SELECT STATDISCRP.TRANSITION FROM STATDISCRP;"

Else If Me.TYPE.Value = "ADSEP" Then
sql = "SELECT STATDISCRP.ADSEP FROM STATDISCRP;"

Else If Me.TYPE.Value = "DISABILITY" Then
sql = "SELECT STATDISCRP.DISABILITY FROM STATDISCRP;"

Else If Me.TYPE.Value = "MENTAL_HEALTH" Then
sql = "SELECT STATDISCRP.MENTAL_HEALTH FROM STATDISCRP;"


End If


// here you filter your other Drop-down menu by changing its Row Source using sql
Me.Combo2.RowSource = sql
May 1 '08 #5

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

Similar topics

5
6518
by: SirPoonga | last post by:
I think I'd have to do a combination of ASP and javascript to do this. What I want to do fill the first drop down box with values from a database query. Then based off that selection fill in the...
1
1602
by: Ann Baker | last post by:
I had to take a Access 97, 2002 and 2003 test for a temp agency. One of the questions was to "filter the hospital macro to show only the hospitals associated with hospital ID #" Can't remember the...
4
1619
by: crispywafers | last post by:
Hi, Is it possible to filter ontop of the current filter being applied to records? This seems like it should be easy? I have two drop down boxes-- one to filter on a student's last name, one...
3
11428
by: Vern | last post by:
The following code retrieves data into a dataset, and then creates a dataview with a filter. This dataview is then attached to a combobox. When the effective date changes, I would like to see the...
0
1251
by: richi | last post by:
Hello I hava an OWC Pivot Table component in an aspx file. I am using VBScript to set properties when the page is loaded. I am setting the order of a field using the OrderedMembers property...
5
14037
by: Hutch | last post by:
Ok so i have a form that is in Continuous view displaying many "Call Logs" A drop down box is located in the header of the form. This box isalready set up to look at the Companys that are designated...
2
3190
by: leeperman | last post by:
In Dreaweaver I cannot filter my database results to display only specific data that is retrieved from mulptile drop down list on my search page. The drop down list selections are posted to my...
7
30471
by: ncsthbell | last post by:
Working on converting some old MS2000 access applications to MS2007. I have many datasheets in the application and I have noticed that on all of them the column headers have a down arrow with...
14
18248
by: mjvm | last post by:
HI, I have had a search for the answer to this question, but I can't transfer what I am reading to my database. I don't know enough about the language required, but have been able to get my...
0
7119
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
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6873
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5453
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
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1400
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.