|
代码一我是用EXCEL-VBA的办法从文本中取数追加到ACCESS, 为了保持ID的连续性,我顺利的求出ACCESS中已存在的 ii=rst.RecordCount
代码二是用于EXCEL-VBA向ACCESS查询,并返回结果到EXCEL, 结果返回是顺利的,但我碰到一个问题:
我希望能用MSGBOX告诉用户本次共检索到几掉记录,可是,Range("a4").CopyFromRecordset rst 虽然能返回结果,
我就是拿不出rst的记录数,rst是对象,用Count 不行,用RecordCount 结果是-1也不行,用for each c in rst 循环做也通不过,所以特向各位前辈请教,烦请指点,谢谢。
代码一(部分)
Dim rst As ADODB.Recordset
Set conn = New ADODB.Connection
conn.Open "Provider = Microsoft.Jet.OLEDB.4.0;Data Source =E:\ACVD0012.mdb;"
Set myTbl = New ADOX.Table
myTbl.Name = "111"
Set rst = New ADODB.Recordset
With rst
.ActiveConnection = conn
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open myTbl.Name
End With
ii = rst.RecordCount '原记录数
代码二(部分)
Dim con As New ADODB.Connection
Dim rst As New ADODB.Recordset
con.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & ThisWorkbook.Path & "\ACVD.mdb;"
rst.Open "SELECT * FROM 111 WHERE acc like '%038'", con, adOpenForwardOnly, adLockReadOnly
Sheet1.Select
Cells.ClearContents
Range("a4").CopyFromRecordset rst
rst.Close
con.Close |
|