devxlogo

Execute Parametrized QueryDefs Simultaneously in DAO

In Microsoft Access, you can execute a parameterized query that uses other parameterized queries, as long as their parameter names are the same. Save these queries in an Access database: “QueryOne”

 PARAMETERS MyDate DateTime;SELECT Date1 FROM TableOne WHERE Date1>MyDate;"QueryTwo"PARAMETERS MyDate DateTime;SELECT Date1 FROM TableTwo WHERE Date1>MyDate;"QueryUnion"PARAMETERS MyDate DateTime;SELECT * FROM QueryOneUNIONSELECT * FROM QueryTwo;

You can execute QueryUnion from VB code by passing the MyDate parameter. This example is for DAO 3.5:

 Sub ExecuteQuery()Dim db As DatabaseDim rs As RecordsetDim qd As QueryDefSet db = OpenDatabase("")Set qd = db.QueryDefs("QueryUnion")qd.Parameters(0).Value = CDate("3/1/00")Set rs = qd.OpenRecordset(dbOpenSnapshot)' <.....>rs.Closedb.CloseEnd Sub

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Five Early Architecture Decisions That Quietly Get Expensive

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.