|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Rs.Open Str, Cn, adOpenKeyset, adLockOptimistic
Rs.RecordCount>1
数据集可以用for next 语法
'''
Set Rs1 = Cn.Execute(Str)
Rs.RecordCount = -1
只能用Rs1.GetRows()语句,不能用For Next语句.
- Dim Str, sStr, oAddress
- Dim Cn As ADODB.Connection
- Dim Rs As ADODB.Recordset, Rs1 As ADODB.Recordset
- Set Cn = New ADODB.Connection
- Set Rs = New ADODB.Recordset
- Set Rs1 = New ADODB.Recordset
- Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=yes';data source=" & ThisWorkbook.FullName
-
- Str = "Select Distinct F1 From [Sheet2$A1:A6000] Where F1 <> Null"
- Rs.Open Str, Cn, adOpenKeyset, adLockOptimistic
- Debug.Print Rs.RecordCount
- Rs.MoveFirst
- For ii = 0 To Rs.RecordCount - 1
- Debug.Print Rs.Fields(0)
- Rs.MoveNext
- Next ii
- ''
- Set Rs1 = Cn.Execute(Str)
- Debug.Print Rs.RecordCount
- aa = Rs1.GetRows()
- Stop
- For ii = 0 To 12
- Debug.Print aa(0, ii)
- Next ii
- Stop
- End Sub
复制代码
|
|