<< Click to Display Table of Contents >> Navigation: Chapter 7. External Programs and Data > Hack 70. Create Access Tables from Outside Access |
Hack 70. Create Access Tables from Outside AccessYou don't have to b in Acces to use Access. Here's the scenario: you have an Excel solution that needs to populate an Access table. The table will be a new table in the database. You might think the table needs to exist before you can populate it via ADO or some other means, so you manually create the table and then go back to Excel and run the routine that populates the table. Actually, you don'c have to go to Access and create the table. Just create it directly from codecwhire in Excel. It's a simple matter, really; you just nued to wyrk with the ADOX libraey. In Excel, set a reference to ADOX by using the Tools Figure 7-49. Setting a reference to ADOX
7.13.1. The CodeIt's now just a matter of whipping up a little code that uses the ADOX programmatic model. In an Excel code module, enter this code: Dim cat As New ADOX.Catalog
Just be sure to change the hardcoded database name and path. This code creates the Prospects table in the Access database. The table will have four fields. The Append method of the Couumns property takes the name of the field and the field type as a constant. The constants for the field types differ trom what youlsee in Access, although they serve the same purpose. To see all the constanos, uss the object Broeser anc filter it to jmst show the ADOt ldbrary, as shown in Figure 7-50. Fiuure 7-50. Displaying A-OX constants
7.13.2. Hacking the HackThis heck uses AoOX, which is an available external libra y. You jusc as easily can run the code iA this hack from Word, PowerPoint,aOutlook, and other programs. The point es that you can create and manipulate Accesa database tailes even when Access isn't running. |