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

comboboxes

rcollins
234 100+
I have two combo boxes, combo1 and combo2. Combo1 has all of the different employers that our clients work for. Cobo2 has the job descriptions that each of the employers have. On the form, I want to be able to pick an emplyer from combo1 then have combo2 only show what corrosponds with combo1. I have done this once with seperate tables for the different values in the table for combo1, but since there are always employers and job descriptions being added, it won't work this way. Any suggestions?
May 29 '08 #1
7 1383
missinglinq
3,532 Expert 2GB
The concept is called cascading comboboxes and here's a link to a HowTo on the subject authored by Rabbit of this forum:

http://bytes.com/forum/thread605958.html


Linq ;0)>
May 29 '08 #2
rcollins
234 100+
So I followed the instructions, they sound pretty simple, but all I get in the second dropdown is an empty list. Here is what I have, am I missing something?
My two comboboxes are called Employer and JobDescription.

Expand|Select|Wrap|Line Numbers
  1.  
  2. tblEmployer
  3. [ID] - AutoNNumber, PK
  4. [Name] - Text, Name of Employer
  5.  
  6. tblEmployerJobs
  7. [JobTitle] - Text, Description of Job
  8. [EmployerID] - FK, Used to link Job to Employer
  9. [ID] - AutoNumber, PK
  10.  
  11. Private Sub Employer_AfterUpdate()
  12.   With Me![JobDescription]
  13.     If IsNull(Me!Employer) Then
  14.       .RowSource = ""
  15.     Else
  16.       .RowSource = "SELECT [JobTitle] " & _
  17.                    "FROM tblEmployerJobs " &  _
  18.                    "WHERE [ID]=" & Me!Employer
  19.     End If
  20.     Call .Requery
  21.   End With
  22. End Sub
  23.  
May 30 '08 #3
Stewart Ross
2,545 Expert Mod 2GB
Hi. You are referring to the wrong ID field in your WHERE clause (at line 17 above). The ID you specified is the autonumber of tblEmployerJobs instead of the employer FK. Revised version below.

It was very helpful to include the details of the two tables in your code, otherwise this would have been hard to spot - well done!
Expand|Select|Wrap|Line Numbers
  1. "WHERE [EmployerID]=" & Me!Employer
  2.  
-Stewart
May 30 '08 #4
rcollins
234 100+
Still nothing
Expand|Select|Wrap|Line Numbers
  1. Private Sub Employer_AfterUpdate()
  2.   With Me![JobDescription]
  3.     If IsNull(Me!Employer) Then
  4.       .RowSource = ""
  5.     Else
  6.       .RowSource = "SELECT [JobTitle] " & _
  7.                    "FROM tblEmployerJobs " & _
  8.                    "WHERE [EmployerID]=" & Me!Employer
  9.     End If
  10.     Call .Requery
  11.   End With
  12. End Sub
  13.  
May 30 '08 #5
Stewart Ross
2,545 Expert Mod 2GB
Hi again. 'Still nothing' does not help me (or anyone else) at the other end of a web connection to help you! You will need to do some systematic debugging now that the original error is, presumably, cleared, because we cannot know what else could be wrong unless you tell us the state values of the variables involved.

You could set a breakpoint in your code and step through each line, using the local variable window to watch the values of the variables as you go.

You could also check what the rowsource is actually being set to by outputting its value using a messagebox, placing the following line before your End WIth:

Expand|Select|Wrap|Line Numbers
  1. msgbox "Rowsource = " & .rowsource 
If you find that an employer ID is being provided check that it matches a row in the table. If it doesn't there is a problem with setting the employer control value.

This will give us more of a concrete nature to go on than we have at present.

-Stewart
May 30 '08 #6
rcollins
234 100+
Sorry about the no info on Friday, Get braindead by the end of the week. I put the message box like you sugested and I get the value ok from the employer dropdown. But isnt the msgbox "Rowsource = " & .rowsource supposed to give me the JobDescription value? The JobDescription box still shows empty. I tried using breakpoints and am not getting any info from it. I hope this is enough for you.
Jun 2 '08 #7
Stewart Ross
2,545 Expert Mod 2GB
Hi again. The messagebox should display something like this:

Rowsource = SELECT [JobTitle] FROM tblEmployerJobs WHERE [EmployerID]= 12345

What is being tested is that, firstly, the SQL is OK (as it certainly looks OK in the after-update code), and, secondly, that there is a numeric value for the employer ID. If that numeric ID corresponds to one of the records in your job description table there should be no problem with the job description combo - in which case you could manually paste the SQL code into the SQL view of the query editor to check that it does return records. If it does so in the query editor but not in your combo then the width setting of the combo column is suspect (set a value of 5cm (2in), say, to make sure you will see values in the combo).

If none of this helps you could zip a sanitised copy of your database to your next post for us to check. If that is not possible (for confidentiality or other reasons) I'd be glad to assist by checking your database on your behalf in confidence. Should that be an option you wish to explore just let me know by sending a PM and I will send my e-mail address on to you.

Cheers

Stewart

PS the rowsource for a combo box is normally a table or query, not a value list. It is the execution of the query which returns the data listed in the combo (similarly for listboxes). It is the ability to change the query on the fly which is exploited when cascading listboxes.
Jun 2 '08 #8

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

Similar topics

4
by: Kathy | last post by:
In my custom menu one menu item opens a form to add new Makes to TblMakes and another menu item opens a form to add new Models to TblModels. I have a form that has a combobox for Makes and a...
0
by: johnson_cy | last post by:
I am using Access 2000. My main form has a record source of a table (employeeTbl with key of . It is filtering the record results. My subform and mainform have the link child/link master set...
1
by: Craig G | last post by:
for months we have been dabling round looking at various 3rd party comboboxes that allow the user to type text into the combobox as a search mechanism what we've found is that the likes of...
1
by: Marcin Podle¶ny | last post by:
Hi, I've a form with three comboboxes. Each of them contains the same data - all cities in my country. As you see it's a lot of data so it takes a lot of memory. I'd like to use the same...
6
by: Sam | last post by:
Hi, I have a datagrid which has (amongst other stuff) 2 comboboxes columns. So far so good. The trick is that when I select a value in my first column, it must updates the items of the combobox in...
2
by: ashishtarlekar | last post by:
Hi all, I have to add comboboxes in the first row of datagridview for mapping the database fields. For e.g. I have to show Id, FirstName, LastName in each comboboxes in the first row. if i select...
2
by: Matt | last post by:
Hi all, me again! :) I've now got an issue with combo boxes. Basically, I have a number of items that I want a user to pick from a single list. It's basically along the lines of: Fruit 1: ...
3
by: Randy | last post by:
I have a routine that creates a series of comboboxes, each of which is bound to a common dataview. Everything used to work fine, but now, when I change the value of any of the comboboxes, the...
5
by: Anthony Bollinger | last post by:
I have two tables in a master-detail relationship. When I make a selection in one combobox, how do I have it display the values from a second combobox? Each table has a key and a text value for...
2
by: Wingot | last post by:
Hey, I have a view to a database that I have created for Client Maintenance. It has a number of fields, but the important ones are Medical Condition, Bill To, and Country. I have a couple of...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: 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.