SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 73 | Next

Jim DeMarco

"Pro Excel 2007 VBA"


1. On the Developer ribbon, choose the Macros command.
2. Select the GetDAOAccessJet macro from the list, and click the Run button. DAO generates
an error, as shown in Figure 2-13.
Figure 2-13. Unrecognized database format error
3. Click the Debug button, and notice that our attempt to instantiate our DAO.Database
object is failing (see Figure 2-14).
CHAPTER 2 n DATA IN, DATA OUT 58
Figure 2-14. OpenDatabase method fires error
DAO Jet, it seems, does not support the new Access database format. Does this mean we
cannot use DAO with *.accdb files? No, it does not. In a short while, we??™ll take a look at how we
can access data from Access 2007 using DAO with ODBC. For now, let??™s continue with Jet.
To make this code work, all we have to do is change the array index in our arr_sPath variable
from 0 to 1.
Set db = Workspaces(0).OpenDatabase(arr_sPath(1), ReadOnly:=True)
Rerun the code, and your worksheet should look like Figure 2-15.
Figure 2-15. The Employees table from the Access 2000 version of the Northwind database
nNote According to the help file, the Range.CopyFromRecordset method will fail if the DAO (or ADO)
recordset contains an OLE object. This seems to be true only sometimes. In the preceding example, we filled
a DAO recordset object with the entire contents of the Employees table from the Access 2000 version of the
Northwind database. This table includes a field named Photo that does contain an OLE object and is included
in the data returned to us.


Pages:
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85