I have a simple select query that can be run against dozens of identically structured tables. Its purpose is to display table data on the screen. (It
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Can I pass an SQL statement to a select query? (Access 2003 / SP1)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Can I pass an SQL statement to a select query? (Access 2003 / SP1)
- This topic has 7 replies, 4 voices, and was last updated 19 years, 9 months ago.
AuthorTopicJohn Littell
AskWoody PlusAugust 22, 2005 at 7:39 pm #423277Viewing 1 reply threadAuthorReplies-
WSHansV
AskWoody Lounger -
John Littell
AskWoody PlusAugust 22, 2005 at 8:55 pm #968077You must have misunderstood my question. I have no problem writing VBA code. I’ve been doing so since Access Version 1. What I’m looking for is a technique, if there is one, to pass SQL (or any other way to define what source table to use) to a pre-defined select query. (I know that I can Open a recordset and display the rows using a data sheet sub-form, but that is to complicated. I simply want to use a query to display the data.)
Thanks, John
-
WSHansV
AskWoody LoungerAugust 22, 2005 at 9:01 pm #968079Sorry about that, I thought you wanted to bypass VBA altogether.
You can use DAO code; you must have a reference to the Microsoft DAO 3.6 Object Library. In the following, qryMyQuery is the name of a pre-defined select query.
Dim strSQL As String
strSQL = ” SELECT … ”
CurrentDb.QueryDefs(“qryMyQuery”).SQL = strSQLYou can also retrieve the current SQL text, and use the Replace function to replace the table name with a different one, then set the SQL property.
-
John Littell
AskWoody PlusAugust 22, 2005 at 9:37 pm #968089Hans,
HooBoy. I haven’t thought about querydefs in years. Consequently, of course, I’d completely forgotten about query properties. (Hey, I’m retired. I forget things.) It looks like the example you’ve given me is exactly what I am looking for. Now for all the querydef reading I can find.Thanks, John
-
-
-
WSNYIntensity
AskWoody LoungerAugust 22, 2005 at 9:07 pm #968082John, I’d try to do this from a form with a multi select list box, selecting the table names from the list box, and modifying your SQL in VBA. To populate a list box with table names, use this code: (Assuming your list name is lstTables)
Private Sub Form_Open(Cancel As Integer)
Dim db As DAO.Database
Dim tdf As TableDefSet db = CurrentDb
For Each tdf In db.TableDefs
lstTables.AddItem tdf.Name
Next tdfEnd Sub
Can you post an example of your SQL?
-
John Littell
AskWoody Plus -
WSpatt
AskWoody Lounger
Viewing 1 reply thread -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
No more rounded corners??
by
CWBillow
1 hour, 9 minutes ago -
No more rounded corners??
by
CWBillow
1 hour, 10 minutes ago -
Android 15 and IPV6
by
Win7and10
4 hours, 56 minutes ago -
KB5058405 might fail to install with recovery error 0xc0000098 in ACPI.sys
by
Susan Bradley
11 hours, 6 minutes ago -
T-Mobile’s T-Life App has a “Screen Recording Tool” Turned on
by
Alex5723
13 hours, 48 minutes ago -
Windows 11 Insider Preview Build 26100.4202 (24H2) released to Release Preview
by
joep517
8 hours, 22 minutes ago -
Windows Update orchestration platform to update all software
by
Alex5723
21 hours, 7 minutes ago -
May preview updates
by
Susan Bradley
8 hours, 30 minutes ago -
Microsoft releases KB5061977 Windows 11 24H2, Server 2025 emergency out of band
by
Alex5723
5 minutes ago -
Just got this pop-up page while browsing
by
Alex5723
13 hours, 19 minutes ago -
KB5058379 / KB 5061768 Failures
by
crown
10 hours, 23 minutes ago -
Windows 10 23H2 Good to Update to ?
by
jkitc
7 hours, 32 minutes ago -
At last – installation of 24H2
by
Botswana12
1 day, 12 hours ago -
MS-DEFCON 4: As good as it gets
by
Susan Bradley
7 hours, 44 minutes ago -
RyTuneX optimize Windows 10/11 tool
by
Alex5723
2 days ago -
Can I just update from Win11 22H2 to 23H2?
by
Dave Easley
1 day, 18 hours ago -
Limited account permission error related to Windows Update
by
gtd12345
2 days, 14 hours ago -
Another test post
by
gtd12345
2 days, 14 hours ago -
Connect to someone else computer
by
wadeer
2 days, 8 hours ago -
Limit on User names?
by
CWBillow
2 days, 12 hours ago -
Choose the right apps for traveling
by
Peter Deegan
2 days, 1 hour ago -
BitLocker rears its head
by
Susan Bradley
1 day, 9 hours ago -
Who are you? (2025 edition)
by
Will Fastie
1 day, 8 hours ago -
AskWoody at the computer museum, round two
by
Will Fastie
2 days, 4 hours ago -
A smarter, simpler Firefox address bar
by
Alex5723
3 days ago -
Woody
by
Scott
3 days, 10 hours ago -
24H2 has suppressed my favoured spider
by
Davidhs
1 day, 9 hours ago -
GeForce RTX 5060 in certain motherboards could experience blank screens
by
Alex5723
4 days ago -
MS Office 365 Home on MAC
by
MickIver
3 days, 18 hours ago -
Google’s Veo3 video generator. Before you ask: yes, everything is AI here
by
Alex5723
4 days, 14 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.