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

Using one drop down box to select contents of another drop down box

3
Hi, I have done a search on this topic but can not find anything that clearly helps with this problem, so bear with me please.

I have a list box that contains a number of options for my staff to choose from. When they choose one of the options I then want another drop down box to be populated with the relevant further options based on their first selection.

Thanks for your help.
Nov 7 '18 #1

✓ answered by twinnyfo

Othafa,

Welcome to Bytes!

You would assign a VBA procedure to the AfterUpdate property of the List box that uses the value of the List box to generate the RowSource Property of the Combo Box. Example below:

Expand|Select|Wrap|Line Numbers
  1. Private Sub lstCompany_AfterUpdate()
  2.     Dim strSQL  As String
  3.  
  4.     strSQL = "SELECT ProductID, ProductName " & _
  5.              "FROM tblCompanyProducts " & _
  6.              "WHERE CompanyID = " & lstCompany & ";"
  7.  
  8.     Me.cboProducts.RowSource = strSQL
  9.     Me.cboProducts.Requery
  10.  
  11. End Sub
Hope that hepps!

6 1301
twinnyfo
3,653 Expert Mod 2GB
Othafa,

Welcome to Bytes!

You would assign a VBA procedure to the AfterUpdate property of the List box that uses the value of the List box to generate the RowSource Property of the Combo Box. Example below:

Expand|Select|Wrap|Line Numbers
  1. Private Sub lstCompany_AfterUpdate()
  2.     Dim strSQL  As String
  3.  
  4.     strSQL = "SELECT ProductID, ProductName " & _
  5.              "FROM tblCompanyProducts " & _
  6.              "WHERE CompanyID = " & lstCompany & ";"
  7.  
  8.     Me.cboProducts.RowSource = strSQL
  9.     Me.cboProducts.Requery
  10.  
  11. End Sub
Hope that hepps!
Nov 7 '18 #2
Othafa
3
Thanks for the prompt reply.

Unfortunately I'm not very good at VBA yet and dont really understand how to use the example in my circumstances. I realise now that I should have explained my setup better.

I have 6 tables that I want to use.
Table 1 is called "Quality Area" and it contains 5 options. Tables 2 to 6 are called "Quality Theme 1", "Quality Theme 2" etc.

I then created a form using the contents of "Quality Area" in a drop down list box and another drop down list box that I want to list data from the relevant "Quality Theme" table


So if a user were to click on option 2 in "Quality Area", the drop down box next to it will be populated with the contents of "Quality Theme 2"

I hope that makes sense.

Thanks.
Nov 7 '18 #3
NeoPa
32,556 Expert Mod 16PB
All the techniques you need for that are included in this article (Cascaded Form Filtering).
Nov 7 '18 #4
NeoPa
32,556 Expert Mod 16PB
We seem to have crossed with our posts.

Your design sounds like a problem. It isn't normalised (See Database Normalisation and Table Structures).

Once that problem's been resolved, and you have all of your Quality Themes in a single table where they belong, you'll find that the other article I linked to will make better sense and you can achieve everything you require.
Nov 7 '18 #5
Othafa
3
Thanks for this NeoPa. I'll have a read and see what I come up with.
Nov 8 '18 #6
NeoPa
32,556 Expert Mod 16PB
Sometimes Normalisation, and the fundamentally different way of thinking about things that databases in particular, and set theory in general, require can be a struggle. Especially for those that are used to other types of logic, such as coders and analysts. Once you get it though, everything fits into place much more easily.

Good luck and I hope you manage to make it make sense.
Nov 9 '18 #7

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

Similar topics

4
by: Nanos | last post by:
For the form I need to create drop down select with say five different options. There also should be possibility to enter own option if one is not listed. How can I do it.? Thank you in advance...
5
by: Jeff | last post by:
Hi, I am trying to set the value of one drop down select box to the value of another drop down select box. I have the following in a function. document.formname.boxto.options.v alue =...
2
by: Nanos | last post by:
Hi all, For the form I need to create drop down select with different options (dynamicly from DB). That's easy in PHP. But there also should be the possibility to enter own option if one is not...
2
by: kmnotes04 | last post by:
Is it possible to link one drop-down box to another? For example, if a name is chosen from a drop-down list, can another drop-down list then automatically display the person's office as a result of...
4
by: Bishop | last post by:
I have a query similar to this: "Select ProductID, ProductName, ProductDescription where MFGID = @MFGID". I use a Drop Down List populated with the MFGID's to populate the @MFGID variable. My...
17
by: KMEscherich | last post by:
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...
3
by: printline | last post by:
Hello All I need some help in a form i'm creating. I have to fields with drop down select boxes. What i want to do is, when a user selects a given value in one drop down, the other drop down...
1
by: metalaniac | last post by:
Hi there I am searching for a method of displaying an extra form field, only when a certain option is selected in a drop down box. <label for="staff_status">Status: </label> <select...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.