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 
SQL query in VBA
Shia G. 
   
3 years ago
I am looking for guidance on how to write a SQL query in VBA that is based on two queries, each with its own date parameters. I want to be able to change these parameters within the VBA code itself. Specifically, I am wondering if there are any TechHelp video that could guide me through this process.
Kevin Yip  @Reply  
     
3 years ago
To set the values of parameters in VBA, you use the syntax as shown in the picture below.  The key thing is that the user won't be able to manually enter the parameter value as you usually do.  The parameter value has to be fed into the query with VBA code as shown in the picture, otherwise you get a run-time error.  Therefore, if you must get an input from the user, you need to do it some other way, such as with the InputBox() function or other form operations.

P.S. Richard would never say this, but if you were my student, I would say that parameter queries are to be avoided.  They cause problem with VBA coding such as this, because user input cannot be used.  You have to get the user's input some other way.  And if you can't have user inputs, you might as well just use regular queries, and avoid parameter queries altogether.  All the domain aggregate functions (DLookup, DMax, DCount, etc.) also don't allow parameter queries.
Kevin Yip  @Reply  
     
3 years ago

Scott Axton  @Reply  
        
3 years ago
Richard Rost  @Reply  
          
3 years ago
Oh, I agree with you, Kevin, that parameter queries are to be avoided - for professional developers. For beginners, it's an easy way to teach them how to specify criteria. For pros, ABSOLUTELY avoid parameter queries.
Richard Rost  @Reply  
          
3 years ago
Shia, what I would recommend you do is instead of creating a query, just create a form with fields for your user to specify the criteria you want, and then build the SQL statement in VBA, and then use that to set the RecordSource property of your form (or another form). See Search Form 2.0 or Access Search Seminar.
Shia G. OP  @Reply  
   
3 years ago
Thanks Richard,You've been the voice I hear most frequently these days

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: 6/9/2026 6:31:06 PM. PLT: 1s