Drop-down list depending on the value of another field

stemar

Board Regular
Joined
Mar 16, 2002
Messages
248
Amongst other tables in my property maintenance database, I have the following:

Jobs: Jobs that need to be done
Job Code, Contractor, etc

Job Types: Types of Job
Job Code, Description

Contractors: List of Contractors who may be given a job
ID, Name, etc.

Contractors & Jobs: Links contractors to the type of jobs they do
ID, Job code

I have a form for entering jobs, and I’d like a dropdown list in the Contractors field that will give a list of contractors who undertake this kind of work, so that if the Job Type code is BD01, the list will give a list of Contractors who do BD01 work. As I understand it, I’ll need a query something like

Select ID code, Name
from Contractors where ID code =
(Select ID code
from Contractors & Jobs
where job code = JobsForm. Job Code)

I know this isn’t right, but my SQL’s very rusty! Can anyone help me get it right? Alternatively, I’m while I’ve never used VB for Access, I’m halfways competent at VBA for Excel. Would I be better off with a VB userform and a button?

I’m using Access 2002 & WinXP Pro
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
You can do this with the barest minimum SQL. In the Combo Box's Properties, go to its Recordsource and click on the three dots. It will then pull up a Query Builder. Add the three tables that you need, join them if they don't automatically join themselves, and pull all of the fields from the tables that you're going to want to see in your combo box. In the criteria of Job Type Code, you're going to have it look at the control on your form which you've populated with the Job Type Code (probably a text box or another combo box, right?):
Code:
Forms!Your_Form.Form!Your_Job_Type_Code_Control

The only thing is that you're going to have to decide exactly when you want this combo to Requery; I'm thinking it will probably be on the Lost_Focus event of the Job Type Code control if it's a text-box or the After_Update event if it's a combo box.
 
Upvote 0

Forum statistics

Threads
1,221,567
Messages
6,160,541
Members
451,655
Latest member
rugubara

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top