从Excel 2010中读取Access 2010中的特定字段

我有以下Excel VBA代码,直到我将Access(2007)数据库转换为Access(2010)数据库,才正常工作。 我已经使用Access(2010)中的一些新function来改善我的数据库,但现在我的Excelmacros将不能运行。 我收到以下消息。

运行时错误3343 Unreconized数据库格式

我认为修复可能是一个简单的修复,但我不是一个程序员,所以我在一个迷失的….在此先感谢您的帮助。

Sub Get_Hardware() 'Retrieves hardware weights from Access database '********Note: If program fails to run, in the visual basic editor, under tools, references, you may ' need to have "Microsoft DAO 3.6 Object Library" downloaded********** ' ******* May also need to register DAO 3.6 if it does not apear in the selectable list by doing the following. ' 1. Open Window's start menu and select "Run" ' 2. Paste the following into the run windo and tell it to run it.... ' regsvr32 "c:\program files\common files\microsoft shared\dao\dao360.dll" Do While Not IsEmpty(ActiveCell.Offset(0, 0)) DAOCopyFromRecordSet "\\fil-ict-07\s0052491$\Engineering\Mass Properties Database (Access 2010)\Mass Properties Database (2010).accdb", "Hardware", "Part Number", ActiveCell ActiveCell.Offset(1, 0).Select Loop End Sub ___________________________________________________________________________________________ Public Sub DAOCopyFromRecordSet(DBFullName As String, TableName As String, _ FieldName As String, TargetRange As Range) Dim db As Database, UW, MC, Des, WQ As Recordset Dim intColIndex As Integer Dim MatCode As String Set TargetRange = TargetRange.Cells(1, 3) Set db = OpenDatabase(DBFullName) 'SQL Query Set UW = db.OpenRecordset("SELECT Std_Parts.UnitWeight FROM Std_Parts WHERE (((Std_Parts.[Part Number]) = '" & _ ActiveCell.Offset(0, 0).Value & "'))", dbReadOnly) Set MC = db.OpenRecordset("SELECT Std_Parts.Material_Code FROM Std_Parts WHERE (((Std_Parts.[Part Number]) = '" & _ ActiveCell.Offset(0, 0).Value & "'))", dbReadOnly) Set Des = db.OpenRecordset("SELECT Std_Parts.Description FROM Std_Parts WHERE (((Std_Parts.[Part Number]) = '" & _ ActiveCell.Offset(0, 0).Value & "'))", dbReadOnly) Set WQ = db.OpenRecordset("SELECT Std_Parts.Qual FROM Std_Parts WHERE (((Std_Parts.[Part Number]) = '" & _ ActiveCell.Offset(0, 0).Value & "'))", dbReadOnly) ' write recordset TargetRange.CopyFromRecordset UW Set TargetRange = TargetRange.Cells(1, 0) TargetRange.CopyFromRecordset Des Set TargetRange = TargetRange.Cells(1, 3) TargetRange.CopyFromRecordset MC Set TargetRange = TargetRange.Cells(1, 22) TargetRange.CopyFromRecordset WQ ActiveCell.Offset(0, 6).Select ActiveCell.Formula = "=RC[-4]*RC[-1]" GoOn: ActiveCell.Offset(0, -6).Select Set UW = Nothing Set MC = Nothing Set Des = Nothing Set WQ = Nothing db.Close End Sub 

您需要对Microsoft Office 12.0 Access Database Engine Object Library的引用,而不是旧的DAO库。