我正在尝试编写代码以在选择每个组合框时更改 3 个组合框。例如:在组合框 1 中,他们选择 Urban,它用 2010 和 2011 填充组合框 2,然后用 houston、austin 等填充组合框 3。我正在尝试使用 If then 循环,但我得到了“无效的限定符”的错误,我不明白,因为它是有效的,它已在整个脚本中使用。任何帮助都会很棒!
Private Sub UserForm_Initialize()
cboStations.Value = "Annual"
cboYear.Value = "2012"
Dim WorkDB As DAO.Database
Dim workRecSetA As DAO.RecordSet
Dim workRecSetB As DAO.RecordSet
Dim x As Integer
Set WorkDB = DBEngine.OpenDatabase("K:\TASS\2 - GEO-DATA PROCESSING SUPPORT\MICHELLE'S WORK_ENTER NOT!!\Work Folder\Map Automation Project\Access Tables\Map_Automation.mdb")
Set workRecSetA = WorkDB.OpenRecordset(Name:="select * from Districts order by District_Name", Type:=dbOpenDynaset)
Do Until workRecSetA.EOF
cboDistrict.AddItem workRecSetA("District_Name")
workRecSetA.MoveNext
Loop
Set workRecSetB = WorkDB.OpenRecordset(Name:="select * from Stations order by Station_Name", Type:=dbOpenDynaset)
Do Until workRecSetB.EOF
cboStations.AddItem workRecSetB("Station_Name")
workRecSetB.MoveNext
Loop
For x = 2010 To 2015
cboYear.AddItem x
Next
End Sub
Private Sub cmdCancel_Click()
frmMapSetUp.Hide
End Sub
Private Sub cboStations_Change()
Dim cboYear As String
If cboStations.Text = "Urban" Then
cboYear.AddItem "2010", "2011", "2012" > Here is where I am receiving the error!!
End If
End Sub
Private Sub cboYear_Change()
Dim cboDistrict As String
If cboYear.Text = "2010" Then
cboDistrict.AddItem "Abilene", "Amarillo", "Austin", "San_Antonio", "Waco", "Wichita_Falls"
Else
cboYear.Text = "2011"
cboDistrict.AddItem "Beaumont", "Houston"
Else
cboYear.Text = "2012" cboDistrict.AddItem "Brownwood", "Bryan", "Childress", "Corpus_Christi", "El_Paso", Lubbock, "Odessa", "Yoakum"
End If
End Sub