excel vba 调用ADODB 问题?

2024-12-21 06:39:50
推荐回答(1个)
回答1:

Dim CNN As New ADODB.Connection
Dim RS1 As ADODB.Recordset
dim strCn as string
dim sql as string

Set RS1 = New ADODB.Recordset
Set CNN = New ADODB.Connection
CNN.CursorLocation = adUseClient
strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Password=123;data source = O:\schedule\BS Schedule\Marco Temp Data\537.mdb;Persist Security Info=True" ----这里你适当改下
CNN.open (strCn )

sql = "select * from tablename "--表明改下
RS1.Open sql, CNN, adOpenKeyset, adLockOptimistic, adCmdText

rs.MoveFirst

For I = 1 To 1000
ComboBox1.AddItem RS1.Fields("品牌")
RS1.MoveNext
Next I

RS1.Close
Set RS1 = Nothing
Set DB1 = Nothing
Exit Sub
100:
MsgBox "找不到符合条件的记录", 1 + 16, "系统提示"

如果不行把 Set RS1 = Nothing
Set DB1 = Nothing 注释掉试试