Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Forum    Comments List
Upload Images | @Reply | Bookmark | Link | Email | Next Unseen |
DateSerial Function Update
Larry Stacy 
     
9 hours ago
I have queries in my Access database using DateSerial for date ranges. (ex. (Between DateSerial(2026,1,1) And DateSerial (2026,1,31). Each year I create a new database by copying the previous year. When I create my 2027 database, is there a vba macro that will change all my queries from 2026 to 2027 in one operation?
Any help will be greatly appreciated
Kevin Robertson  @Reply  
          
9 hours ago
Why are you creating a new database for each year?
Kevin Yip  @Reply  
     
6 hours ago
The current year can be evaluated from the expression Year(Now), and the previous year is Year(Now)-1.  So you can plug that into your query's SQL expression.
Kevin Robertson  @Reply  
          
6 hours ago
Also, if you are using DateSerial() to get the whole month, does that mean you have 12 Queries that do exactly the same thing? What if you need to add an additional field to the Query? You would need to add that field to 12 separate objects in your database. Do you also add that field to your back catalog of databases for each Query for previous years. This can quickly become a maintenance nightmare.
Alkan Toykan  @Reply  
       
2 hours ago
While I completely agree with both Kevin regarding database architecture and best practices, I would assume that, as a developer student, you have already grasped these concepts by now. That said, let me explain how we can solve the specific problem under the assumption that creating a new database every year might be driven by company policy, periodic archiving, data isolation, or specific business logic.
Rather than replacing every occurrence of 2026 in the SQL text, I would iterate through the database's saved queries using DAO's QueryDefs collection and use a regular expression to target only occurrences where 2026 is the first argument of a DateSerial() call. This would leave other occurrences of 2026 elsewhere in the SQL untouched. The expression should also account for optional spaces between DateSerial, the opening parenthesis, and the year argument.
I'd back up the query definitions first and test the changes on a copy of the database before applying them to the production version.
Add a Reply Upload an Image
Next Unseen

 
 
What's This?

 

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: 10/18/2026 6:10:40 PM. PLT: 0s