Computer Learning Zone CLZ Access Excel Word Windows

From out there on the moon, international politics look so petty. You want to grab a politician by the scruff of the neck and drag him a quarter of a million miles out and say, "Look at that!"

-Edgar Mitchell, Apollo 14
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access SQL Seminar Part 2    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Syntax
Marc S 

11 years ago
Hi Richard.
In response to your inquiry for future seminars and access lessons, I would suggest an comprehensive seminar on syntax. I always understand what i need to put in my sql statement but I always err when it come to the syntax. I loose hours on a missing space or quotation mark. It's quite frustrating to waste time on syntax, wish there was a complete guide somewhere.  

For a specific example : on a form I have two buttons that load a report based on the value loaded in txt box.

The first button loads the report based on on an id (number) works great.
WHERE "[RubricID]=" & [GbselectedrubricID]

The second button loads the report according to a second text box (date).
WHERE "[Dateofeval]=" & "#" & [GBdateselected] & "#"

These two button work great on their own but when I combine them into one
WHERE "[Dateofeval]=" & "#" & [GBdateselected] & "#" AND "[RubricID]=" & [GbdateselectedID]
Does not work, logically it should work I do not understand why, I blame it on syntax.
Marc


Reply from Alex Hedley:

You need to be careful with where your quotes are.
1 tip would be to write the whole WHERE in quotes first
"WHERE [RubricID]=1"
Now you want to replace the 1 with a variable x
"WHERE [RubricID]=" & x

WHERE "[RubricID]=" & [GbselectedrubricID]
=>
"WHERE [RubricID]=" & [GbselectedrubricID]

You need to move the quote here and you don't need the extra &
WHERE "[Dateofeval]=" & "#" & [GBdateselected] & "#"
=>
"WHERE [Dateofeval]=#" & [GBdateselected] & "#"

WHERE "[Dateofeval]=" & "#" & [GBdateselected] & "#" AND "[RubricID]=" & [GbdateselectedID]
=>
"WHERE [Dateofeval]=#" & [GBdateselected] & "# AND [RubricID]=" & [GbdateselectedID]

Do you see how you've closed your quote too early
& "#" AND "[Ru ...

Another option is to build the Query first in the Query Builder.
Change to SQL View
Copy Paste this into your VBA, then switch out the values for variables

You could also build your strSQL string then
Debug.Print strSQL
Then you can see what you've built.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access SQL Seminar Part 2.
 

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 3:58:52 AM. PLT: 0s