还可改成这样: Private Sub UserForm_Initialize() Dim DBpath As String Dim iCount As Integer Dim i As Integer DBpath = "provider=Microsoft.jet.OLEDB.4.0;data source=" & ThisWorkbook.Path & "\data.mdb" & "" If CNN.State = 1 Then CNN.Close CNN.Open DBpath
strSQl = "select 省份 from 资料 group by 省份" RST.Open strSQl, CNN, adOpenKeyset, adLockPessimistic iCount = RST.RecordCount arr = RST.GetRows ComboBox1.List = Application.WorksheetFunction.Transpose(arr) RST.Close End Sub Private Sub ComboBox1_AfterUpdate() ComboBox2.Clear strSQl = "select 城市 from 资料 where 省份 = '" & UCase(ComboBox1.Value) & "'" RST.Open strSQl, CNN, adOpenKeyset, adLockPessimistic arr = RST.GetRows ComboBox1.List = Application.WorksheetFunction.Transpose(arr) RST.Close End Sub |