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 SQL Server Lessons    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
PT Query Select Statment
Greg Rosoff 
    
2 years ago
Stupid Question:

I want to specify the fields/columns pulled in by the query defs statement below, about 25 fields.

CurrentDb.QueryDefs("qry_SUT_begin_Date_PT").SQL = "SELECT  * FROM tbl_DMHRSI_STAFF_PRD WHERE TI_CD='" & cmb_SUT_TI_CD & "' AND Date_Pulled='" & cmb_SUT_Begin_Date & "'"

Is there an easy way to hit Return to keep all the Select Fields in the window's view?
Richard Rost  @Reply  
           
2 years ago
I don't understand. Once you modify the SQL statement in the querydef, then just open the query like normal with Docmd.Openquery.
Greg Rosoff OP  @Reply  
    
2 years ago
The string of fields is too long
Greg Rosoff OP  @Reply  
    
2 years ago
This is the string of fields I want to pull from the table, but I don't know how to specifically list them out as the string is too long
SELECT TBL_DMHRSI_STAFF_PRD.DATE_PULLED, TBL_DMHRSI_STAFF_PRD.TI_CD, TBL_DMHRSI_STAFF_PRD.EDIPI, TBL_DMHRSI_STAFF_PRD.DUPLICATE_EDIPI, TBL_DMHRSI_STAFF_PRD.DMHRSI_EMP_NUM, TBL_DMHRSI_STAFF_PRD.FULL_NAME, TBL_DMHRSI_STAFF_PRD.PERSON_TYPE, TBL_DMHRSI_STAFF_PRD.TITLE_RANK, TBL_DMHRSI_STAFF_PRD.UPDATED_EMAIL, TBL_DMHRSI_STAFF_PRD.VALIDATED_EMAIL, TBL_DMHRSI_STAFF_PRD.NOT_IN_GLOBAL, TBL_DMHRSI_STAFF_PRD.IN_GLOBAL_NO_EMAIL, TBL_DMHRSI_STAFF_PRD.PERSON_UIC_OR_PAS, TBL_DMHRSI_STAFF_PRD.ORGANIZATION_NAME, TBL_DMHRSI_STAFF_PRD.PERSON_EFFECTIVE_START_DATE, TBL_DMHRSI_STAFF_PRD.PERSON_EMAIL_ADDRESS, TBL_DMHRSI_STAFF_PRD.POSITION_EFFECTIVE_START_DATE, TBL_DMHRSI_STAFF_PRD.POSITION_TITLE, TBL_DMHRSI_STAFF_PRD.SUPERVISOR_FULL_NAME, TBL_DMHRSI_STAFF_PRD.SUPERVISOR_EDIPI, TBL_DMHRSI_STAFF_PRD.SUPERVISOR_EMAIL, TBL_DMHRSI_STAFF_PRD.PERSON_SERVICE, TBL_DMHRSI_STAFF_PRD.PERSON_GRADE
FROM TBL_DMHRSI_STAFF_PRD

Sami Shamma  @Reply  
             
2 years ago
WOW
Greg Rosoff OP  @Reply  
    
2 years ago
BTW, Thank you for even looking at this on a Saturday!
Richard Rost  @Reply  
           
2 years ago
I don't understand, again. Your object names above are completely meaningless, so why don't you explain to me in English what everything represents, or rewrite it so someone who doesn't understand your names can comprehend it. What's a cmb_SUT_TI_CD? No clue. See: All About Context
Richard Rost  @Reply  
           
2 years ago
If it's one table, you could start by removing the table name from each of the fields. You don't need it in a single-table query.
Richard Rost  @Reply  
           
2 years ago
Next, shorten those field names up. If you don't want to modify the original table, create a query and Alias them.

FN is better than TBL_DMHRSI_STAFF_PRD.FULL_NAME
Greg Rosoff OP  @Reply  
    
2 years ago
The string of field names is too long to post into VBA
Greg Rosoff OP  @Reply  
    
2 years ago
Okay, was wondering if there was a similar function to a VBA script " _" I had missed in your earlier classes.
Sami Shamma  @Reply  
             
2 years ago
Greg,

Read and follow the advice from Richard above.
Richard Rost  @Reply  
           
2 years ago
OK, then shorten it (see 2 previous suggestions).
Richard Rost  @Reply  
           
2 years ago
Oh, well, yeah, you could break that up into multiple strings with _ if you want.

X = "SELECT this, that, the, other, thing " & _
"FROM mytable"


Greg Rosoff OP  @Reply  
    
2 years ago
or if there was a way to just edit the WHERE clause while leaving the SELECT & FROM Statements alone in the underlying Pass Through Query
Richard Rost  @Reply  
           
2 years ago
I think your BEST BET is to make a View on the server with shorter field names.
Greg Rosoff OP  @Reply  
    
2 years ago
Does the " _" hold even within the SELECT Statement? For instance having multiple rows within just that statement?
Greg Rosoff OP  @Reply  
    
2 years ago
Roger that.  It isn't my table, but can certainly pull in a new view on the server side.  Thanks to both of you for your input!

THa
Richard Rost  @Reply  
           
2 years ago
Sure. You're just creating a string. Make the string first, then you can MsgBox it to make sure it's correct, and then assign it to your querydef. But I still think you'll benefit from smaller field names.
Greg Rosoff OP  @Reply  
    
2 years ago
Thank you!  Get back to the beers and brats and I am very grateful for the weekend input.
Richard Rost  @Reply  
           
2 years ago
I took last week off to go to Jamaica... so I'm catching up this week. :)
Greg Rosoff OP  @Reply  
    
2 years ago
That was time well spent. BTW, are you doing courses on Python?
Christopher Hankwembo  @Reply  
  
2 years ago
I have assumed that you already declared the variable for the record set , then simply use the code like below + a criteria:

Set rst = db.OpenRecordset("select vsdcRcptPbctDate,rcptNo,intrlData,rcptSign,sdcId,SqrCode FROM [tblCustomerInvoice] WHERE [InvoiceID] = " & Me.txtJsonReceived)

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

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: 6/16/2026 2:56:33 PM. PLT: 1s