Data comes from a propriatry source. It can be exported to Excel. Then it is imported into Access. Currently ther are over 70 individual tables. All tables have the same number of fields, alot. We only need 5 or 6 fields..
The question is can you run a query which ask for the TABLE name first, then uses the 5 fields that we really need.
Paul
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Query from multiple tables
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Query from multiple tables
- This topic has 11 replies, 3 voices, and was last updated 13 years, 3 months ago.
AuthorTopicWSpaweaver
AskWoody LoungerMarch 14, 2012 at 10:05 am #482190Viewing 5 reply threadsAuthorReplies-
WSMarkLiquorman
AskWoody Lounger -
WSpaweaver
AskWoody Lounger
-
-
WSjohnhutchison
AskWoody LoungerMarch 14, 2012 at 5:19 pm #1324965I am not sure, but it sounds like each query only actually uses one table.
If so there are two questions.-
[*]How do you put a list of tables onto a form
[*]If you choose a table from the list, how do you have the query use that table.Neither task is trivial
1
This SQL will produce a list of tables. You could use this to create a query called qryTables, then put a combo on a form with a RowSource of qryTables. Call the combo comboTablesCode:SELECT MSysObjects.Name FROM MSysObjects WHERE (((MSysObjects.Type) In (1,4,6)) AND ((Left([Name],4))”MSYS”) AND ((Left([Name],1))”~”));
If you don’t actually want all the tables listed then you would need some way of restricting this list.
2
First create a query using any of the tables. It does not matter which. Save it as something…qryMyQuery.
Then use code like this. Put this behind a command button.Code:Dim strTable as string Dim SQL as string If not isnull(me.comboTables) then strTable = me.comboTables SQL = “Select fieldname1, fieldname2, fieldname3, fieldname4, fieldnamet5 from ” & strTable & “Order by fieldname1” Currentdb.queryDefs(“qryMyQuery”).sql = SQL Docmd.Openquery “qryMyQuery” else msgbox “Select a table from the list” end if
You need to replace the fieldnames in the above with your actual fieldnames.
This code rewrites qryMyquery each time to use the table you want. You only ever have one query, but it keeps changing.(I have written this code without testing it as I write, so I may have made a typo or some other error. Post back if something does not work.)
-
WSpaweaver
AskWoody LoungerMarch 15, 2012 at 11:43 am #1325067
-
-
WSjohnhutchison
AskWoody LoungerMarch 15, 2012 at 4:23 pm #1325203Whenever you create a query, Access stores the query as a piece of SQL. In normal use you don’t see it, but you can look at it ( and edit if you want) by switching to SQL view of a query. You don’t say what version of Access you use…the method of viewing the SQL is slightly different in different versions. In 2007 and 2010 it is under View on the Home tab.
So start to create a new query the normal way. The Show Table dialog pops up for you to add tables to the query. Close it without adding any tables, then immediately switch to SQL view of this query.
You will just see Select; Delete this and paste in the SQL I posted.
Test the query works by switching to datasheet view. Save it as (say) qryTables. -
WSpaweaver
AskWoody LoungerMarch 15, 2012 at 10:15 pm #1325274I get a compile error with the SQL.. I’m using 2010
30390-asseccerror
-
-
WSjohnhutchison
AskWoody Lounger -
WSpaweaver
AskWoody LoungerMarch 16, 2012 at 9:24 am #1325321new challenge. create a blank database and imported tables only. The query above now works.
At the step of creating a FORM ……then put a combo on a form with a RowSource of qryTables. …….
using the combo box wizard I get ” no valid fields can be found in qryTables, please select a new source”Also, the first Record is showing f_4F9F14BD3CC24FC9BD1EEA8B81596AC8_Data” instead of a actual table
-
WSjohnhutchison
AskWoody LoungerMarch 16, 2012 at 4:47 pm #1325417then put a combo on a form with a RowSource of qryTables. …….
using the combo box wizard I get ” no valid fields can be found in qryTables, please select a new source”I get the same thing. I had not tested this as it did not occur to me that there would be a problem with this.
Here is a workaround. Change the Row Source Type of your combo to Value List then use the following code to fill the values from the query. The code goes in the On Load event of the form. Don’t repeat the Private Sub Form_Load() and the End sub.Code:Private Sub Form_Load() Dim strTableList As String Dim db As DAO.Database Dim rs As DAO.Recordset Set db = CurrentDb Set rs = db.OpenRecordset(“qryTables”, dbOpenSnapshot) If Not rs.EOF Then rs.MoveFirst Do While Not rs.EOF strTableList = strTableList & rs(“Name”) & “;” rs.MoveNext Loop strTableList = Left(strTableList, Len(strTableList) – 1) ‘ Substitute the name of your combo box Me.Combotables.RowSource = strTableList End If ‘ Clean up rs.Close Set rs = Nothing Set db = Nothing End Sub
Also, the first Record is showing f_4F9F14BD3CC24FC9BD1EEA8B81596AC8_Data” instead of a actual table
Don’t know what to make of that. Get your database to show you Hidden and System objects, so you can see the full list of Tables.
Right Click on the top of the Navigation Bar and choose Navigation Options.
30397-NavOptions
Then tick the boxes for Show Hidden Objects and Show System Objects. See what you can find.
Look in MySysObjects (That is the table the query uses.)
-
-
-
WSpaweaver
AskWoody Lounger -
WSjohnhutchison
AskWoody Lounger
Viewing 5 reply threads -

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
-
The 16-billion-record data breach that no one’s ever heard of
by
Alex5723
18 minutes ago -
Weasel Words Rule Too Many Data Breach Notifications
by
Nibbled To Death By Ducks
54 minutes ago -
Windows Command Prompt and Powershell will not open as Administrator
by
Gordski
4 hours, 9 minutes ago -
Intel Management Engine (Intel ME) Security Issue
by
PL1
7 hours, 6 minutes ago -
Old Geek Forced to Update. Buy a Win 11 PC? Yikes! How do I cope?
by
RonE22
1 hour, 16 minutes ago -
National scam day
by
Susan Bradley
19 minutes ago -
macOS Tahoe 26 the end of the road for Intel Macs, OCLP, Hackintosh
by
Alex5723
1 day ago -
Cyberattack on some Washington Post journalists’ email accounts
by
Bob99
1 day, 1 hour ago -
Tools to support internet discussions
by
Kathy Stevens
1 day, 8 hours ago -
How get Group Policy to allow specific Driver to download?
by
Tex265
17 hours, 3 minutes ago -
AI is good sometimes
by
Susan Bradley
1 day, 9 hours ago -
Mozilla quietly tests Perplexity AI as a New Firefox Search Option
by
Alex5723
23 hours, 12 minutes ago -
Perplexity Pro free for 12 mos for Samsung Galaxy phones
by
Patricia Grace
2 days, 9 hours ago -
June KB5060842 update broke DHCP server service
by
Alex5723
2 days, 7 hours ago -
AMD Ryzen™ Chipset Driver Release Notes 7.06.02.123
by
Alex5723
2 days, 12 hours ago -
Excessive security alerts
by
WSSebastian42
1 day, 2 hours ago -
* CrystalDiskMark may shorten SSD/USB Memory life
by
Alex5723
2 days, 21 hours ago -
Ben’s excellent adventure with Linux
by
Ben Myers
14 hours, 38 minutes ago -
Seconds are back in Windows 10!
by
Susan Bradley
2 days, 8 hours ago -
WebBrowserPassView — Take inventory of your stored passwords
by
Deanna McElveen
1 day, 2 hours ago -
OS news from WWDC 2025
by
Will Fastie
12 hours, 22 minutes ago -
Need help with graphics…
by
WSBatBytes
1 day, 16 hours ago -
AMD : Out of Bounds (OOB) read vulnerability in TPM 2.0 CVE-2025-2884
by
Alex5723
3 days, 12 hours ago -
Totally remove or disable BitLocker
by
CWBillow
2 days, 12 hours ago -
Windows 10 gets 6 years of ESU?
by
n0ads
2 days, 15 hours ago -
Apple, Google stores still offer China-based VPNs, report says
by
Nibbled To Death By Ducks
3 days, 23 hours ago -
Search Forums only bring up my posts?
by
Deo
4 hours, 38 minutes ago -
Windows Spotlight broken on Enterprise and Pro for Workstations?
by
steeviebops
1 hour, 11 minutes ago -
Denmark wants to dump Microsoft for Linux + LibreOffice
by
Alex5723
15 hours, 35 minutes ago -
How to get Microsoft Defender to honor Group Policy Setting
by
Ralph
8 hours, 35 minutes 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.