The Problem (Q-score 9, ranked #7th of 67 in the Access VBA archive)
The scenario as originally posted in 2008
Hi I need to create a query in MSAccess 2003 through code (a.k.a. VB) — how can I accomplish this?
Why this Access DoCmd / Recordset path keeps breaking
The scenario uses DoCmd or OpenRecordset, both of which are notorious for bubbling silent failures when the source query has uncommitted changes. The question captures a common debugging dead-end in Access VBA.
The Verified Solution — elite answer (top 10 %%) (+19)
5-line Access VBA pattern (copy-ready)
A vague answer for a vague question 🙂
strSQL="SELECT * FROM tblT WHERE ID =" & Forms!Form1!txtID
Set qdf=CurrentDB.CreateQueryDef("NewQuery",strSQL)
DoCmd.OpenQuery qdf.Name
When to Use It — vintage (14+ years old, pre-2013)
A top-10 Access VBA pattern — why it still holds up
Ranks #7th of 67 in the Access VBA archive. The only pattern ranked immediately above it is “Determine whether a Access checkbox is checked or not” — compare both if you’re choosing between approaches.
What changed between 2008 and 2026
The answer is 18 years old. The Access VBA object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.