#2
cwa99582023-09-25 09:15
|
Dim conn As ADODB.Connection
Private Sub Form_Load()
' 获取连接
Set conn = GetDBConnection()
' 绑定第一个下拉框
Dim rs1 As New ADODB.Recordset
rs1.Open "SELECT DISTINCT Field1 FROM myTable", conn, adOpenStatic, adLockReadOnly
If Not rs1.EOF Then
Do While Not rs1.EOF
Combo1.AddItem rs1.Fields("Field1").Value
rs1.MoveNext
Loop
End If
rs1.Close
' 关闭记录集对象
Set rs1 = Nothing
End Sub
Private Sub Combo1_Change()
' 获取第一个下拉框的选定值
Dim selectedValue As String
selectedValue = Combo1.Text
' 清空第二个下拉框
Combo2.Clear
' 创建新的数据库连接和记录集对象
Dim conn As ADODB.Connection
Set conn = GetDBConnection()
Dim rs2 As New ADODB.Recordset
' 绑定第二个下拉框
rs2.Open "SELECT Field2 FROM myTable WHERE Field1='" & selectedValue & "'", conn, adOpenStatic, adLockReadOnly
If Not rs2.EOF Then
Do While Not rs2.EOF
Combo2.AddItem rs2.Fields("Field2").Value
rs2.MoveNext
Loop
End If
rs2.Close
' 关闭记录集对象和数据库连接
Set rs2 = Nothing
conn.Close
Set conn = Nothing
End Sub
请老师帮忙看看是 什么原因呢
只有本站会员才能查看附件,请 登录