Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

execute a query using DAO

Status
Not open for further replies.

dcarbone

Programmer
Aug 22, 2003
29
CA
I'm trying to execute a query which contains sub queries in VB access.

az is the query name

Set rst = db.Execute(az)

also just copying out the sql code from the query to the vb access code does not work
 
also the query requires a parameter to be passed to it
 
Because it's already in Access, you need to run the query there, not in your code ... something like this

Dim Qry As QueryDef
Set Qry = db.QueryDefs(az)
Qry("ParameterName") = "123"
Set rs = qdf.OpenRecordset(dbOpenDynaset)

The Execute statement doesn't return recordsets. It is intended for running SQL that doesn't return anything like "Delete", "Update", etc.
 
You need to use a querydef to do this...here's an example from one of my dbs:

Dim RST As Recordset, QDF As QueryDef, SSQL As String

SSQL = "SELECT DISTINCTROW ProcessGroup.Employee_ID FROM..."

Set QDF = CurrentDb.CreateQueryDef("", SSQL)
QDF.Parameters("EnterDepartment") = DepartmentCriteria
QDF.Parameters("EnterDate") = DateCriteria
Set RST = QDF.OpenRecordset(dbOpenDynaset)

Hope that helps.

Kevin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top