|
chyidc 发表于 2013-12-6 23:54
对了,老师,如果想统计出rs里面复制过来的记录总数怎么办?
msgbox s里面怎么体现出来呢? - Sub Getdate()
- Dim cnn As Object, rs As Object, SQL As String
- Set cnn = CreateObject("adodb.connection")
- Set rs = CreateObject("adodb.recordset")
- cnn.Open "Provider=Microsoft.Ace.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.Path & "\text1.xlsx"
- SQL = "select " & Join([a1:h1&""], ",") & " from [Sheet1$] where 日期>#" & Range("a" & Rows.Count).End(xlUp) & "#"
- rs.Open SQL, cnn, 1, 3
- If rs.RecordCount > 0 Then
- s = "共更新记录" & rs.RecordCount & "条,分别是:"
- SQL = "select 日期,count(*) from [Sheet1$] where 日期>#" & Range("a" & Rows.Count).End(xlUp) & "# group by 日期"
- Range("a" & Rows.Count).End(xlUp).Offset(1).CopyFromRecordset rs
- Set rs = CreateObject("adodb.recordset")
- rs.Open SQL, cnn, 1, 3
- For i = 1 To rs.RecordCount
- s = s & vbCrLf & rs.Fields(0).Value & "更新" & rs.Fields(1).Value & "条"
- rs.MoveNext
- Next
- MsgBox s
- End If
- rs.Close
- cnn.Close
- Set rs = Nothing
- Set cnn = Nothing
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|