If you want to link or make dependent two or more combo boxes in user form . For Example -
In above case when you select any zone . It should show all locations from selected zone only.
Add below code to the form event
Option Compare Database
' Rep_Name is table name which is having list of all zones and locations
Private Sub Combo0_Change()
' combo6 - location box
' Rep_Name.location - Rep_Name is table and location is field name(column header) having list of locations
Combo6.Value = ""
Combo6.RowSource = "SELECT DISTINCT Rep_Name.location FROM Rep_Name WHERE (((Rep_Name.[zone])='" & Combo0.Value & "'));"
End Sub
Private Sub Form_Load()
' combo0 - zone box
' Rep_Name.zone - Rep_Name is table and zone is field name(column header) having list of zones
Combo0.RowSource = "SELECT DISTINCT Rep_Name.Zone FROM Rep_Name"
End Sub
Private Sub Form_Open(Cancel As Integer)
Combo0.Value = ""
Combo6.Value = ""
End Sub
Download Working File
In above case when you select any zone . It should show all locations from selected zone only.
Add below code to the form event
Option Compare Database
' Rep_Name is table name which is having list of all zones and locations
Private Sub Combo0_Change()
' combo6 - location box
' Rep_Name.location - Rep_Name is table and location is field name(column header) having list of locations
Combo6.Value = ""
Combo6.RowSource = "SELECT DISTINCT Rep_Name.location FROM Rep_Name WHERE (((Rep_Name.[zone])='" & Combo0.Value & "'));"
End Sub
Private Sub Form_Load()
' combo0 - zone box
' Rep_Name.zone - Rep_Name is table and zone is field name(column header) having list of zones
Combo0.RowSource = "SELECT DISTINCT Rep_Name.Zone FROM Rep_Name"
End Sub
Private Sub Form_Open(Cancel As Integer)
Combo0.Value = ""
Combo6.Value = ""
End Sub
No comments:
Post a Comment