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

Drop-down 1 leading to drop-down 2

Microsoft Access '97
Using VBA code

Have been asked to include a drop-down list which will retrieve the options from lookup table 1, then according to what the end-user selects from this drop-down, I need it to go to lookup table 2 with those specific options and record both selections in a table. Right now, I have a table for each option and corresponding catetory in order to ensure there are no mistakes for each category they want. But, if I can simplify the database with this, then it will be a LOT cleaner for the end-user. I can always create new tables and delete existing ones if needed.

Is there a way to accomplish this???

Thank you in advance for your time and assistance.

K Escherich
Jun 24 '07 #1
17 1780
missinglinq
3,532 Expert 2GB
The concept is called Cascading Comboboxes.You should take a look at Rabbit's tutorial on the subject:

Cascading Combo/List Boxes

Good Luck!

Linq
Jun 24 '07 #2
The concept is called Cascading Comboboxes.You should take a look at Rabbit's tutorial on the subject:

Cascading Combo/List Boxes

Good Luck!

Linq

Hi there, tried the information and it seems it does not work. Have any other ideas?

Thank you
Jun 24 '07 #3
ADezii
8,834 Expert 8TB
Microsoft Access '97
Using VBA code

Have been asked to include a drop-down list which will retrieve the options from lookup table 1, then according to what the end-user selects from this drop-down, I need it to go to lookup table 2 with those specific options and record both selections in a table. Right now, I have a table for each option and corresponding category in order to ensure there are no mistakes for each category they want. But, if I can simplify the database with this, then it will be a LOT cleaner for the end-user. I can always create new tables and delete existing ones if needed.

Is there a way to accomplish this???

Thank you in advance for your time and assistance.

K Escherich
You must be much more specific than this. Post the Names of the Combo Boxes, the RowSources for the Combos, Bound Column for each Combo, what 2 Fields are you writing to the Table, what is the Table Name, Data Types for the Fields in the Combos, etc. I would also take missingling's advice again and read the Reference on Cascading Combo Boxes.
Jun 24 '07 #4
You must be much more specific than this. Post the Names of the Combo Boxes, the RowSources for the Combos, Bound Column for each Combo, what 2 Fields are you writing to the Table, what is the Table Name, Data Types for the Fields in the Combos, etc. I would also take missingling's advice again and read the Reference on Cascading Combo Boxes.

Hi there, I created 2 tables (T_STATE and T_CITY)

State = STATE_ID, STATE
City = CITY_ID, CITY, STATE_ID

Data in tables
STATE = California, Texas, Nevada
CITY = Los Angeles, San Francisco, San Diego
Austin, Houston, Dallas
Las Vegas, Reno
STATE_ID = CA, TX, NV

CONTROL 1 = State and bound column = STATE_ID
CONTROL 2 = City and no bound column

I linked the two table using STATE_ID in the relationships view.
I created a form with 2 unbound controls (combo & list boxes) and it seems that it did not work with either type of list.



Private Sub Form_Current()
Me.LST_STATE.RowSource = "SELECT T_STATE.STATE_ID, T_STATE.STATE FROM T_STATE"
End Sub

This works FINE. When you open the form, you see both columns of data like you should.

On the AfterUpdate option for CONTROL1, I placed the following code and all I get is a Parameter window

Private Sub LST_STATE_AfterUpdate()
With Me.LST_CITY
If IsNull(Me.LST_STATE) Then
.RowSource = ""
Else
.RowSource = "Select City from T_CITY where State_ID = " & Me.LST_STATE
End If
Call .Requery
End With
End Sub

I am testing this code in Access 2003, could this be the cause??? I am testing this so I can take it to work tomorrow.

Thank you again for your assistance.
Jun 24 '07 #5
ADezii
8,834 Expert 8TB
Hi there, I created 2 tables (T_STATE and T_CITY)

State = STATE_ID, STATE
City = CITY_ID, CITY, STATE_ID

Data in tables
STATE = California, Texas, Nevada
CITY = Los Angeles, San Francisco, San Diego
Austin, Houston, Dallas
Las Vegas, Reno
STATE_ID = CA, TX, NV

CONTROL 1 = State and bound column = STATE_ID
CONTROL 2 = City and no bound column

I linked the two table using STATE_ID in the relationships view.
I created a form with 2 unbound controls (combo & list boxes) and it seems that it did not work with either type of list.



Private Sub Form_Current()
Me.LST_STATE.RowSource = "SELECT T_STATE.STATE_ID, T_STATE.STATE FROM T_STATE"
End Sub

This works FINE. When you open the form, you see both columns of data like you should.

On the AfterUpdate option for CONTROL1, I placed the following code and all I get is a Parameter window

Private Sub LST_STATE_AfterUpdate()
With Me.LST_CITY
If IsNull(Me.LST_STATE) Then
.RowSource = ""
Else
.RowSource = "Select City from T_CITY where State_ID = " & Me.LST_STATE
End If
Call .Requery
End With
End Sub

I am testing this code in Access 2003, could this be the cause??? I am testing this so I can take it to work tomorrow.

Thank you again for your assistance.
  1. It would be more efficient to set the Row Source Property for [LST_STATE} in the Properties Sheet as opposed to the Form's Current Event where it would have to be re-evaluated for each Record.
  2. The Bound Column for [LST_STATE] is [STATE_ID], a String (CA, TX, NV), so you need to modify the syntax for the creation of the Row Source to:
    Expand|Select|Wrap|Line Numbers
    1. .RowSource = "Select City from T_CITY where State_ID = '" & Me.LST_STATE & "'"
Jun 25 '07 #6
  1. It would be more efficient to set the Row Source Property for [LST_STATE} in the Properties Sheet as opposed to the Form's Current Event where it would have to be re-evaluated for each Record.
  2. The Bound Column for [LST_STATE] is [STATE_ID], a String (CA, TX, NV), so you need to modify the syntax for the creation of the Row Source to:
    Expand|Select|Wrap|Line Numbers
    1. .RowSource = "Select City from T_CITY where State_ID = '" & Me.LST_STATE & "'"

Hi there, I just tested it out and it now works!! THANK YOU VERY MUCH for your assistance.
Jun 25 '07 #7
Hi there, I just tested it out and it now works!! THANK YOU VERY MUCH for your assistance.

Hi there, I forgot to ask, once you make the first selection and the 2nd list appears in the 2nd window, is there a way to capture the selction from the first and a selction from the second window in a table??

Thank you.
Jun 25 '07 #8
ADezii
8,834 Expert 8TB
Hi there, I just tested it out and it now works!! THANK YOU VERY MUCH for your assistance.
You're quite welcome.
Jun 25 '07 #9
ADezii
8,834 Expert 8TB
Hi there, I forgot to ask, once you make the first selection and the 2nd list appears in the 2nd window, is there a way to capture the selction from the first and a selction from the second window in a table??

Thank you.
Are you asking to capture both values from the Combo Boxes, namely [State_ID] and [City] then write them to a Table? If the answer is yes, this would have to be done from the AfterUpDate() Event of the 2nd Combo Box. If you don't know how to accomplish this, let me know.
Jun 25 '07 #10
Are you asking to capture both values from the Combo Boxes, namely [State_ID] and [City] then write them to a Table? If the answer is yes, this would have to be done from the AfterUpDate() Event of the 2nd Combo Box. If you don't know how to accomplish this, let me know.
YES, I would like to capture the 2 selected values. Let's say someone selects CALIFORNIA as the state and SAN FRANCISCO for the city. I would like to see those 2 values appear in the two tables accordingly. Unfortunately, I don't know how to accomplish this. Can you show me???


State = STATE_ID, STATE
City = CITY_ID, CITY, STATE_ID

Data in STATE tables
STATE_ID = CA, TX, NV
STATE = California, Texas, Nevada

Data in CITY tables
CITY_ID = LAX, SFO, SAN, AUS, HOU, DAL, LAS, RNO
CITY = Los Angeles, San Francisco, San Diego,Austin, Houston, Dallas
Las Vegas, Reno
STATE_ID = CA, TX, NV


CONTROL 1 = State and bound column = STATE_ID
CONTROL 2 = City and no bound column

I hope this helps.

Thank you once again for your assitance.
Jun 25 '07 #11
ADezii
8,834 Expert 8TB
YES, I would like to capture the 2 selected values. Let's say someone selects CALIFORNIA as the state and SAN FRANCISCO for the city. I would like to see those 2 values appear in the two tables accordingly. Unfortunately, I don't know how to accomplish this. Can you show me???


State = STATE_ID, STATE
City = CITY_ID, CITY, STATE_ID

Data in STATE tables
STATE_ID = CA, TX, NV
STATE = California, Texas, Nevada

Data in CITY tables
CITY_ID = LAX, SFO, SAN, AUS, HOU, DAL, LAS, RNO
CITY = Los Angeles, San Francisco, San Diego,Austin, Houston, Dallas
Las Vegas, Reno
STATE_ID = CA, TX, NV


CONTROL 1 = State and bound column = STATE_ID
CONTROL 2 = City and no bound column

I hope this helps.

Thank you once again for your assitance.
You're welcome for the assistance. Here is the remainder of your question - any further questions, feel free to ask.

I'm not sure of the mechanism by which you want to add the data to a Table,
but here it is demonstrated in the AfterUpdate() Event of the City Combo Box.
Remember, the Bound Field in cboState is [STATE_ID], so you cannot use Me![cboState],
because you want to write the State, not the State_ID to the Table.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboCity_AfterUpdate()
  2. Dim MyDB As DAO.Database, MyRS As DAO.Recordset, intRet As Integer
  3.  
  4. If Not IsNull(Me![cboState].Column(1)) And Not IsNull(Me![cboCity]) Then
  5.   'You can name your Table/Fields anything you like. I just named then tblStateCity with
  6.   '[State] and [City] as Fields in the Table.
  7.   intRet = MsgBox("Add State and City to tblStateCity", vbQuestion + vbYesNo + vbDefaultButton1, "Add Record")
  8.     If intRet = vbYes Then
  9.       Set MyDB = CurrentDb()
  10.       Set MyRS = MyDB.OpenRecordset("tblStateCity", dbOpenTable)
  11.         MyRS.AddNew
  12.           MyRS![State] = Me![cboState].Column(1)
  13.           MyRS![City] = Me![cboCity]
  14.         MyRS.Update
  15.           MyRS.Close
  16.     End If
  17. End If
  18. End Sub
Jun 26 '07 #12
You're welcome for the assistance. Here is the remainder of your question - any further questions, feel free to ask.

I'm not sure of the mechanism by which you want to add the data to a Table,
but here it is demonstrated in the AfterUpdate() Event of the City Combo Box.
Remember, the Bound Field in cboState is [STATE_ID], so you cannot use Me![cboState],
because you want to write the State, not the State_ID to the Table.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboCity_AfterUpdate()
  2. Dim MyDB As DAO.Database, MyRS As DAO.Recordset, intRet As Integer
  3.  
  4. If Not IsNull(Me![cboState].Column(1)) And Not IsNull(Me![cboCity]) Then
  5.   'You can name your Table/Fields anything you like. I just named then tblStateCity with
  6.   '[State] and [City] as Fields in the Table.
  7.   intRet = MsgBox("Add State and City to tblStateCity", vbQuestion + vbYesNo + vbDefaultButton1, "Add Record")
  8.     If intRet = vbYes Then
  9.       Set MyDB = CurrentDb()
  10.       Set MyRS = MyDB.OpenRecordset("tblStateCity", dbOpenTable)
  11.         MyRS.AddNew
  12.           MyRS![State] = Me![cboState].Column(1)
  13.           MyRS![City] = Me![cboCity]
  14.         MyRS.Update
  15.           MyRS.Close
  16.     End If
  17. End If
  18. End Sub

Hi there, THANK YOU VERY MUCH for your assistance. As I am reviewing the code, am wondering if there should be a button on the form. And if so, should all of this code be associated with a button?
Jun 26 '07 #13
Hi there, THANK YOU VERY MUCH for your assistance. As I am reviewing the code, am wondering if there should be a button on the form. And if so, should all of this code be associated with a button?
I finally got it to work. I want to THANK YOU VERY, VERY MUCH for your assistance.
Jun 26 '07 #14
ADezii
8,834 Expert 8TB
I finally got it to work. I want to THANK YOU VERY, VERY MUCH for your assistance.
The other Moderators/Experts and myself are also glad to be of assistance.
Jun 26 '07 #15
The other Moderators/Experts and myself are also glad to be of assistance.
By the way, where are you folks located??? Are you overseas or here in the US?
Jun 26 '07 #16
By the way, where are you folks located??? Are you overseas or here in the US?
Hi there, am wondering if you can help me once again?

Am attempting the following

I have a main table that has a primary key (SRI). I developed two tables
LT_KEY_FACTORS TABLE
FACTOR_ID
FACTOR

LT_SUB_FACTORS TABLE
SUB_FACTOR_ID
SUB_FACTOR
FACTOR_ID

T_FACTORS TABLE (This is the table that will capture the data when someone clicks on a line item in the second panel.
FACTOR_ID
KEY_FACTOR
SUB_FACTOR
SRI

I need to pull in the SRI from the main table so I can see how many key factors and sub factors are tied to a specific SRI. I have a MAIN table where the SRI is the PRIMARY KEY.

When I run this like we did using the STATE and CITY tables it works fine. However, when I attempt to pull in a third table that contains the SRI (MAIN TABLE). It does not work. Can you please tell me where I am going wrong??

Thank you
Jun 26 '07 #17
MMcCarthy
14,534 Expert Mod 8TB
By the way, where are you folks located??? Are you overseas or here in the US?
US is home but the site is international. Admins, moderators and experts come from all over the world.
Jun 27 '07 #18

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

Similar topics

2
by: André Almeida Maldonado | last post by:
Hey guys, I'm trying to populate a dropdownlist with this code: cmdCommand.CommandText = "SELECT cliecodi, clienome FROM clientes" cmdCommand.CommandType = CommandType.Text dtrReader =...
3
by: JIK | last post by:
Hi, I'm looking for a multi-select dropdown to use in my asp.net/C# app. Anybody have a tip? Jon
4
by: AccessRookie | last post by:
Ok, I am pretty new to Access (Using Access 2002 at my job). Here is what I want to do. I want to create a database that has a form. On this form will be a dropdown menu (combobox). Depending...
0
by: Kay | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp...
0
by: Kay O'Keeffe | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp...
0
by: acadam | last post by:
Hi, I am trying to use cascading dropdown but I have some problems. The firts dropdown is ok, it's filled regularly... but the second dropdown is still disabled!! Why? I tried to start my...
3
by: Ninio | last post by:
I have a simple form with a dropdown menu that consists of 3 option and each option should retrieve a query from a database. i have been looking all over the place and can't seem to find how to do...
13
by: Shutey | last post by:
I have a strange issue with dropdowns. Using php4, mySQL5, Apache 2 on a fast XP pro PC, I have a form which requires 5 dropdowns populated with indentical values. I extract the values using SQL...
1
by: redgoals | last post by:
Hi, I have searched the forum for a similar problem but have been unable to find anything. What i am trying to achieve is a dropdown menu which behaves in the following way: 1, Someone...
16
by: AFSSkier | last post by:
I have several cascading ComboBoxes & would like to close Cbo2 & open Cbo1 when there is an error. These CboBoxes are on an Excel spreadsheet, not a UserForm. I have the following code, if the...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.