當前位置:成語大全網 - 新華字典 - excel vba 調用ADODB 問題?

excel vba 調用ADODB 問題?

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 註釋掉試試