Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Data Base Select Query Column
Jeffrey Hebert 
    
3 years ago
Table 1 has a field where I store a field name that corresponds to one of nine field names in Table 2 (Table 2 has a total of 20 fields). I want the Query to return the data for a subset of records in Table 2 from the field identified in Table 1. I can get the subset returned with the data with all nine fields displayed but I don't know how to limit the return to just the data from a specific field. I feel like I should be able to write an expression that tells the Query to return the data from [Table_2]![Field_X] where Field_X = [Table_1]![Name of the Table_2 Field]. Sorry if this is confusing.  Jeff
Scott Axton  @Reply  
        
3 years ago
I suggest getting the value for the query first.  Then open the query using the value you entered.

Check out Value From a Form
Kevin Yip  @Reply  
     
3 years ago
To do this, your field name needs to be stored in a variable.  In SQL Server, this can be done.  In VBA, also.  But not in the Access query designer.

In VBA, you can store the field name in a string variable, then construct an SQL with string concatenation:

    Dim s1 As String, s2 as String, r As Recordset
    s = "FirstName"
    s2 = "SELECT " & s1 & " FROM Table_2"
    Set r = CurrentDb.OpenRecordset(s2)
Jeffrey Hebert OP  @Reply  
    
3 years ago
Thanks Kevin, I'm afraid that VBA is currently over my head.  
Thanks Scott, I will check that out to see if it is cleaner than my current solution below. I had tried using the value from a Form function earlier but I don't think I had the syntax correct.  

In the mean time I did manage to (possibly) solve the problem by building a long series of imbedded IIF statements.  It makes for a very long statement but it appears to be working at the moment.  Finger Crossed.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/6/2026 11:22:08 AM. PLT: 1s