It is quite common to have a combo box from which you can choose a list of options, which then causes a second combo box to offer a list of options which are dependant on the first combo box.
The example below illustrates this.
Assumptions
Assume we have two simple tables as below:
Tables
TblManufacturers
LngManufacturerId û Autonumber û PK
StrManufacturerName
TblModels
LngManufacturerId û Long ) PK
LngModelId û Autonumber )
StrModelName
Combo Boxes
We have two combo boxes (cboManufacturer and cboModel) the two combo boxes are on a form (Form2) so
CboManufacturer RowSource: [color red] SELECT tblManufacturers.lngManufacturerId, tblManufacturers.strManufacturerName
FROM tblManufacturers
ORDER BY tblManufacturers.strManufacturerName;[/color]
ColumnCount: 2
ColumnWidths: 0;2.54cm
LimitToList: Yes
Events:
Code:
Private Sub cboManufacturer_AfterUpdate()
cboModel.Requery
End Sub
CboModel RowSource: [color red]SELECT tblModels.lngModelId, tblModels.strModelName, tblModels.lngManufacturerId
FROM tblModels
WHERE (((tblModels.lngManufacturerId)=[Forms]![Form2]![cboManufacturer]))
ORDER BY tblModels.strModelName;[/color]
ColumnCount: 3
ColumnWidths: 0;2.54;0
LimitToList: Yes
Events:
[color red]Private Sub cboModel_GotFocus()
If Len(Trim(Nz(cboManufacturer, "") & "")) = 0 Then
MsgBox "Please Specify Manufacturer first"
cboManufacturer.SetFocus
Else
cboModel.Requery
End If
End Sub[/color]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.