Office中国论坛/Access中国论坛
标题:
Excel不引用DAO直接对Access数据库操作
[打印本页]
作者:
盗梦
时间:
2015-4-4 10:05
标题:
Excel不引用DAO直接对Access数据库操作
本帖最后由 盗梦 于 2015-4-4 10:07 编辑
一般Excel要读写Access数据库,需要引用DAO或ADO数据库操作组件以下方法 是不引用DAO对数据库操作 (摘录自网络)
Sub DaoWithoutReferences() '定义变量.
Dim dbEng As Object
Dim Db As Object
Dim Rs As Object '使用OLE方式创建dbEngine对象。Set the dbEng object using OLE
Set dbEng = CreateObject("DAO.DBEngine")
'NOTE: In Microsoft Excel 97, use this line of code instead of the 'above line of code: '
' Set dbEng = CreateObject("DAO.DBEngine.35") '打开数据库 Open a database. Note that the statement contains the dbEng object.
Set Db = _
dbEng.workspaces(0).opendatabase("c:\MSOffice\Access" & _
"Samples\Northwind.mdb") '在数据库中打开记录信 Open a recordset in the database.
Set Rs = Db.openrecordset("Customers")
'获取数据库记录数 Perform a move last and find the number of records 'in the database to test if the operation worked.
Rs.movelast
MsgBox Rs.recordcount
Set Rs = Nothing
Set Db = Nothing
Set dbEng = Nothing
End Sub
复制代码
作者:
fatman
时间:
2015-4-13 14:21
谢谢您的分享!
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3