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 
The perils of working with dates
Alan Hill 

12 years ago
I thought this would be easy but nothing ever is, for me anyway.
I used Dlookup when the form opens to read the perameters values stored in a table. No problems.
Sometimes the user makes silly typos like 1/2/2011 when the range is between 2013 and 2014
When he runs the report date to date the records never show up.
Note the date layout may seem strange I live in Australia. Beautiful one day, perfect the next. (Except for fires and floods)

Private Sub IsDate_BeforeUpdate(Cancel As Integer)
If IsDate < StartDatePerameter OR IsDate > EndDatePerameter Then
MsgBox IsDate & vbNewLine & "Date Is Out Of Range"
     Cancel = True
     Me!IsDate.Undo
End If
' does not work
End Sub

So I hard coded the dates to see if that worked. It did not

Private Sub IsDate_BeforeUpdate(Cancel As Integer)
If IsDate < "#1/7/2013#" OR IsDate > "#30/6/2014#" Then
MsgBox IsDate & vbNewLine & "Date Is Out Of Range"
     Cancel = True
     Me!IsDate.Undo
End If
' does not work
End Sub

Finally I tried something I have never come across before DateValue()

Private Sub IsDate_BeforeUpdate(Cancel As Integer)
If IsDate < DateValue(StartDatePerameter) Or IsDate > DateValue(EndDatePerameter) Then
    MsgBox IsDate & vbNewLine & "Date Is Out Of Range"
    Cancel = True
    Me!IsDate.Undo
End If

' IT WORKS. Access evaluates correctly
End Sub

I hope this may be of help to someone
Regards Alan Hill



Reply from Richard Rost:

Thanks for sharing. Looks like your parameter values are being treated like strings. DateValue converts them to actual date values. I use the CDATE() function which works very similar. The reason why your hard coded values didn't work is because you used quotes TOO. Just: #1/5/2001# not "#1/5/2001#"

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/15/2026 4:29:24 AM. PLT: 1s