• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Using VBA to Run Queries

You can run queries from VBA in a number of different ways. You can run either SQL strings or queries that are already stored in your database in a variety of ways. Table 12.1 shows some common methods of running queries that are available to you.

Table 12.1. Ways to Run Queries from VBA
Action, Method, or Object Object Runs From Source Example
runSQL action DoCmd SQL string
docmd.runSQL strSQL 

OpenQuery action DoCmd Stored query
docmd.OpenQuery 
"qryTotals" 

OpenRecordset method (DAO) Connection or database SQL string or stored query
db. 
OpenRecordset 
strSQL 

Open method (ADO) Connection or recordset SQL string, stored query or stored procedure
rs.Open "SELECT 
* FROM 
Customers, cn 

Execute method (DAO) Connection or database SQL string
db.execute 
strSQL 

Execute method (ADO) Connection or command SQL string
cnn. 
execute strSQL 

QueryDef (DAO stored query) Connection or database Stored query
db.QueryDefs 
("qryTotals") 



PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint