Using Access 2007 to connect to external database and using SQL to limit data before importing to Access 2007 database

I am using Access 2007. I have created an ODBC connection. Using the External Data tab I can manually select my ODBC connection and link to a Table in an external database. Currently the table that I'm interested has massive amount of data and I would like to use filtering criteria using SQL to limit the data before importing to access 2007.
Is it possible to do the same in VBA so that I can AUTOMATICALLY open the ODBC connection and AUTOMATICALLY limit the data using SQL query before downloading to Access 2007 database? If you can help with the code and briefly explain what the code does/how it works, that would be very helpful! Thanks.  TSL
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeOwner, Developing Solutions LLCCommented:
You don't say what you are connecting to.  But must RDBMS software (SQL Server, Oracle, MySQL) allow you to create views within those systems that you can link to, which perform the joins and filter the data and return smaller recordsets from the server to Access.

Depending on what you want to do with the data, you could also create Access pass-through queries, which return non-updateable recordsets, but which allow you to apply filters on the server, to pull significantly smaller recordsets across to Access.  

If you provide more information regarding the back-end database and what you are trying to accomplish, I'm certain one of the Access experts will be able to provide more detail.
Gustav BrockCIOCommented:
Just create a query with your filtering. Save this.
Now use this as source for your import rather than importing the table.

You can also create a pass-through query where you send the SQL directly to the server. Any filtering will then be done on the server which can be faster.

In theory, Access attempts to pass through ALL queries so although a pass-through query eliminates the local Jet processing to construct the SQL string being passed, the query itself should end up being the same and will be processed on the server.  The server will only return the requested rows.  

Of course, there are situations where you can prevent Access from "passing through" a query so you need to be aware of what would cause that.  Two common situations are using UDF or VBA functions that don't have T-SQL equivalents in the query's where clause.  This will cause Access to request the unfiltered recordset and then apply the criteria locally.  Another common one is joining a server-side table to a Jet/ACE table.  Although this is fabulous technology and necessary at times, make sure you understand the ramifications - Access will request the entire server-side table and then perform the join locally.

The one place where using a pass-through query can make a huge difference is with bulk deletes and occasionally bulk updates.  Access encloses all action queries inside a transaction.  You can tell that because before the action is committed, Access asks if you are sure you want to perform the action.  A pass-through query avoids this.  But of course, you don't get a do-over.  Once you send the delete/update to the server, you can color the rows gone/updated.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.