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 
Dates for last week
Darren Barson 
   
4 years ago
have created a search form with several fields to search on and it works wonderfully after watching some of your great videos. There are two date searches: Date1 and Date2 so that I can search for records between dates. I have also created several buttons to automatically add the correct dates for month and year to date. I have also created a button to input the dates for last week. I have used the following code and wondered if there is a more elegant block of code that would be shorter? This code worked on Monday and Tuesday, but now it is putting 29/12/1899 into the Date1 field.  Here is my code:

    Select Case LNumber
  
    Case Weekday(Date) = 2
        Date1 = Date - Date - 1
        Date2 = Date - Weekday(Date, vbMonday)
    Case Weekday(Date) = 3
        Date1 = Date - 8
        Date2 = Date - Weekday(Date, vbMonday)
    Case Weekday(Date) = 4
        Date1 = Date - 9
        Date2 = Date - Weekday(Date, vbMonday)
    Case Weekday(Date) = 5
        Date1 = Date - 10
        Date2 = Date - Weekday(Date, vbMonday)
    Case Weekday(Date) = 6
        Date1 = Date - 11
        Date2 = Date - Weekday(Date, vbMonday)
    Case Weekday(Date) = 7
        Date1 = Date - 12
        Date2 = Date - Weekday(Date, vbMonday)
    Case Weekday(Date) = 1
        Date1 = Date - 13
        Date2 = Date - Weekday(Date, vbMonday)
      
End Select

Richard Rost  @Reply  
          
4 years ago
This line looks like a problem:

Date1 = Date - Date - 1

Darren Barson OP  @Reply  
   
4 years ago
Wow Richard you are fast :-) I think this was a typo and not what is actually in the code in my database. The code worked brilliantly Monday and Tuesday, but stopped working today. I have re-written the code using if then statements which does seem to be working but I thing that select case would be better. If you ever do a class that addresses this in the future then I would be very grateful and look forward to watching it. Thank you so much for a fast response. Your classes are awesome.
Richard Rost  @Reply  
          
4 years ago
Just happened to catch my eye. :)

It doesn't matter what structure you use... If/Then or Select Case. They both do pretty much the same thing. It's not like you're processing millions of records per minute and every clock cycle counts. If it works, it works.
Darren Barson OP  @Reply  
   
4 years ago
Thank you so much for your help, I appreciate it :-)

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 8:04:39 AM. PLT: 2s