ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Import Data from an Access DB with VBA (https://www.excelbanter.com/excel-programming/424215-import-data-access-db-vba.html)

Sandy

Import Data from an Access DB with VBA
 
Is there a primer on how to do this? I want to import specific ranges of
records from an access table.

Thanks,

Sandy

joel

Import Data from an Access DB with VBA
 

The best thing to do is to get a good book on Access VBA. The Access VBA
commands can be used in Excel VBA with a few minor changes. Depending on the
version of Access you are using depends on which commands will work. Access
is not like Excel that most commands will work in any version of Excel. With
Acces you can use the Microsoft Jet engine or use ADO or DAO methods
depending on how the database was created.

1) In Excel declare an Access Application

Set obj = CreateObj("Access.Application"). the include obj in front of the
Access commands yo get from the book.

2) In excel specify a reference to Access by going to the following menu

Tools - References - Microsoft Access 11.0 Object Library

3) Depending on the methods you use in Accdess you may have to add the
Active X library object to your project

Tools - References - Microsoft ActiveX Data Objects 2.8 Library


The two tricks I use is to Reference the Access VBA help for finding
methods. There are a lot of good examples in the Access VBA Help. I also
use the Excel macro recorder and first try to record will performing the
following actions in excel

From worksheet menu in excel : Data - Import External Data - Import Data (or
new web query) and select the Access Source File.

The last menu (the one with finish) has an option to edit the query where
you will see the SQL statements for the query. The "Command Text" portion of
the recorded macro is the SQL statements and can be edited as required. If
you have experience writing SQL statements the task should be pretty simple
once you have the recorded macro to get you started.

"Sandy" wrote:

Is there a primer on how to do this? I want to import specific ranges of
records from an access table.

Thanks,

Sandy



All times are GMT +1. The time now is 09:44 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com