在省份里选择一个省份,城市里面出现该省份下的城市选项。该如何写 100
先做一张access表 ,表名为:城市
加一个Adodc1控件 ,链接表格
Private Sub Combo1_Click() 'Combo1为省份
Combo2.Clear 'Combo2为城市
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "select * from 城市" '连接城市表
Adodc1.Refresh '刷新连接
Do While Not Adodc1.Recordset.EOF
Combo2.AddItem Adodc1.Recordset.Fields(Combo1.Text)
Adodc1.Recordset.MoveNext
Loop
Combo2.Text = Combo2.List(0)
End Sub
在EXCEL里做城市的表不行吗?插入组合框不行吗?
帮你写好了,先工程-部件-引用
Private Sub Combo1_Click()
Combo2.Clear
Dim xlApp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Set xlApp = New Excel.Application
xlApp.Visible = False
Set xlbook = xlApp.Workbooks.Open("" + App.Path + "\城市.xls")
Set xlsheet = xlbook.Worksheets(1)
For b = 1 To 10
For i = 2 To 10
If xlsheet.Cells(1, b).Value = Combo1.Text Then
Combo2.AddItem xlsheet.Cells(i, b)
End If
Next
Next
xlbook.Close
End Sub
Private Sub Form_Load()
Dim xlApp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Set xlApp = New Excel.Application
xlApp.Visible = False
Set xlbook = xlApp.Workbooks.Open("" + App.Path + "\城市.xls")
Set xlsheet = xlbook.Worksheets(1)
For a = 1 To 10
Combo1.AddItem xlsheet.Cells(1, a)
Next
Combo1.Text = Combo1.List(0)
xlbook.Close
End Sub