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 
Days Aged up to current day
Keith Stanton 
    
3 years ago
Hello,

I am trying to use the VBA code from the Work Days Tech Tip video to calculate the # of days past due minus the weekends and holiday various entries are.

The query works, without the days late calculation, once I try to call the daysaged function all I get in my query for the DaysLate result is #Error

I have tried various options unsuccessfully.

I believe I need to equate EndDate to Current Date but am having trouble finding the right way to do so.  Can someone assist?


code
Public Function DaysAged(DueDate As Date, EndDate As Date) As Long
'Public Function DaysAged(DueDate As Date, Now() As Date) As Long   'Doesn't work
'Public Function DaysAged(DueDate As Date) As Long   'Doesn't work

'DueDate is in my table and query

'EndDate is not a field in my table or query, I'm trying to calculate the count of
'how many days past due date up to and including today is minus(-) weekends and holidays

    Dim D As Date, H As Long
    'Dim EndDate As Date ' Doesn't help
    
    DaysAged = 0
    D = DueDate
    'EndDate = "#" & Now() & "#"  'Doesn't work
    'EndDate = "#" & Date & "#"   'Doesn't work
    'EndDate = Date               'Doesn't work
    'EndDate = Day(Date)          'Doesn't work
    'EndDate = Day()              'Doesn't work
        
    While D <= EndDate
    ' Monday through Friday
        If Weekday(D) > 1 And Weekday(D) < 7 Then DaysAged = DaysAged + 1
        D = D + 1
    Wend
    
    ' Holidays in table
        H = Nz(DCount("*", "HolidaysT", "BETWEEN #" & DueDate & _
            "# AND #" & EndDate & "#"), 0)
    DaysAged = DaysAged - H
End Function



Regards,
Keith.
Kevin Robertson  @Reply  
          
3 years ago
If EndDate is always the current date you don't need to send it as a parameter.
Try this:

Public Function DaysAged(DueDate As Date) As Long

    Dim D As Date, EndDate As Date. H As Long
    
    DaysAged = 0
    D = DueDate
    EndDate = Date

    'your other code

End Function


When you call the function you only need to send it DueDate.
Keith Stanton OP  @Reply  
    
3 years ago
Perfect!!!   That worked!!!  Thank You!!!
Kevin Robertson  @Reply  
          
3 years ago
You're welcome.

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: 4/30/2026 5:20:26 PM. PLT: 0s