This process is called cascading combo boxes. There is a tutorial
here but I have made my own tutorial specific to your needs which is listed below:
- Firstly create two tables:
- TableNumbers
-
[ID] – AutoNumber, PK
-
[Number] – Number, This is your 1, 2, or 3
-
-
TableWords
-
[ID] – Autonumber, PK
-
[Word] – Text, This is your Alfa, Bravo, Charlie, ect
-
[NumID] – FK, Used to link the word to the number
Now enter your values you stated before (1, 2 & 3 into TableNumbers, and Alfa, Bravo, Charlie, ect with the corresponding numbers into the TableWords).
- Then on the form where you want the combo boxes, you need to create the combo box containing the numbers. Create a combo box (without wizard) called "Combo1":
Row Source – TableNumbers
Column Count – 2 (We use 2 columns because we want to include both ID and Number)
Column Widths – 0cm;2cm (We set the first column to 0” because the user does not need to see the ID)
Bound Column – 1 (We bind it to the first column so that when we refer to [Combo1], it will return the ID rather than Number)
Then create another combo called "Combo2" but leave this one blank the coding later will put the data into it.
- What we want is to change the Row Source of [Combo2] whenever the user makes a change of selection to [Combo1].
So, in the After Update event property of [Combo1], you’ll want to change it to [Event Procedure].
Then, click on the "..." button to bring up the Visual Basic Editor. In the module, put in the following code:
- Private Sub Combo1_AfterUpdate()
-
With Me![Combo2]
-
If IsNull(Me!Combo1) Then
-
.RowSource = "SELECT [Word] " & _
-
"FROM TableWords "
-
Else
-
.RowSource = "SELECT [Word] " & _
-
"FROM TableWords " & _
-
"WHERE [NumID]=" & Me!Combo1
-
End If
-
Call .Requery
-
End With
-
Forms!Form1!Combo2 = ""
-
End Sub
Now when 1 is selected in Combo1, Alfa, Bravo & Charlie will be in Combo 2.
When 2 is selected, David, Echo, Fox & Golf will appear.
When 3 is selected Honey, Item & Jack will appear.
When Combo 1 is blank, all of the values appear in Combo2.