devxlogo

Execute Parametrized QueryDefs Simultaneously in DAO

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
See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

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.

About Our Journalist