Article ID: 304323 - View products that this article applies to.
This article was previously published under Q304323
Moderate: Requires basic macro, coding, and interoperability skills.
This article applies only to a Microsoft Access database (.accdb and .mdb).
This article shows you how to create an SQL pass-through query in Microsoft Visual Basic for Applications (VBA) with Microsoft ActiveX Data Objects (ADO).
You can write a function in Visual Basic for applications that creates an SQL pass-through query. An SQL pass-through query is made up of an SQL statement and a connection string. When you run the query, it sends commands directly to the database server for processing. This removes the overhead of the Microsoft Jet database engine.
With the Data Access Object (DAO) model, you could use SQL pass-through queries to improve performance when you accessed external data. With ADO, you can use the Microsoft OLE DB Provider for SQL Server to directly access a SQL Server without the overhead of Microsoft Jet or ODBC. You can also use the Microsoft OLE DB Provider for ODBC to access data in any ODBC data source.
Although you no longer have to create SQL pass-through queries in your Microsoft Jet database to improve performance, you can still do so by using ADOX and the Jet Provider. The following code shows you how to create an SQL pass-through query.
NOTE: The sample code in this article uses both ADO and ActiveX Data Objects Extensions for Data Definition Language and Security (ADOX). For this code to run properly, you must click References on the Tools menu in the Visual Basic Editor and make sure that the following two references are selected:
Microsoft ActiveX Data Objects 2.1 LibraryMicrosoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. To create an SQL pass-through query in code, follow these steps:
Microsoft ADO Ext. 2.6 for DDL and Security
For more information about Microsoft OLE DB properties, visit the MSDN Library at the following Microsoft Web site:
http://msdn2.microsoft.com/en-us/library/default.aspxIn the Contents tree in the left pane of the MSDN Library, browse to the following Help topic:
\Data Access \Microsoft Data Access Components \ADO \SDK Documentation \Microsoft ActiveX Data Objects (ADO) \ADO Programmer's Guide \Section V: Appendixes \Appendix A: Providers \Microsoft OLE DB Provider for Microsoft Jet
Contact us for more help
Connect with Answer Desk for expert help.