比如连接当前文件下的数据库.accdb,表名为“宏站”记得先引用。
代码如下:
Sub AC()Dim cnn As New Connection
Dim rs As New Recordset
Dim sql As String
cnn.Open "Provider=Microsoft.Ace.OleDB.12.0dataSource=" & app.Path & "\数据库.accdb"
sql = "select * from [宏站] "
rs.Open sql, cnn
[a1].CopyFromRecordset rs
EndSub
'Access2007 OR Access2010strDSN = "Provider=Microsoft.ACE.OLEDB.12.0User ID=AdminData Source=" &App.Path &"\data\诊断.accdbPersist Security Info=FalseJet OLEDB:Database Password=''"
'strDSN = "Provider=Microsoft.Jet.OLEDB.4.0Data Source=" &App.Path &"\pcdb1.mdbPersist Security Info=FalseJet OLEDB:Database Password=''" 'Access2003
ssal="select * from 表1 "
On Error Resume Next
If rst.State = 1 Then rst.Close
rst.CursorLocation = adUseClient
rst.Open ssql, strDSN, adOpenDynamic, adLockOptimistic
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)