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 Developer Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Date comparison problem in SQL
Astrid Hoogeveen 
    
3 years ago
I have a combobox where the rowsource is a dynamically constructed SQL Select statement.
This selection includes a comparison between a date field from the form and a date field from the query from which the SQL statement selects rows.
This date comparison is not working properly.

This is my dynamic SQL select statement:-
"SELECT DISTINCT fieldA, fieldB FROM QueryName WHERE EffectiveFromDate <= #" & CourseStartDate & "# AND PrincipalTrainer ORDER BY fieldB;"

Where
- EffectiveFromDate is a date field in the Form
- CourseStartDate is a date field from the database query I have called QueryName
- PrincipalTrainer is a boolean true/false field also from the database query

The selection in my code does not work for the case where the dates are in the same year:  
so when EffectiveFromDate = 01/05/2022 (dd/mm/yyyy format) and CourseStartDate = 03/10/2022, the record is not selected.

But when the EffectiveFromDate is in a previous year, it does work.
so when EffectiveFromDate = 01/05/2021 (dd/mm/yyyy format) and CourseStartDate = 03/10/2022, the record is selected.

Can you please let me know what is wrong with my code?

Please note that this is on a UK PC where the date format in Windows is dd/mm/yyyy.
Kevin Robertson  @Reply  
          
3 years ago
You will need to use the Format function for CourseStartDate.
Message box the SQL to see what date is being returned.

I used to also have this problem which is why I switched to the ISO Date Format.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer 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/7/2026 6:21:56 AM. PLT: 1s