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 
Turnaround Time Issue Please Help
Debra Triolo 
     
17 months ago
I have been using the following code (and also a table that houses the holidays) to calculate turnaround time in my database. It works great, and properly excludes holidays and weekends.  I would like to have it so that if something is turned around on the same day it calculates that TAT as 0. Currently it is counting it as 1 day. I tried editing the +1 to -1 in the code below but all that did was continuously crash everything out. Here is the code:

Function WorkingDays(ByVal fromDate As Date, ByVal toDate As Date) As Long

If IsNull(fromDate) Or IsNull(toDate) Then
            WorkingDays = 0
            Exit Function
        End If

    While fromDate <= toDate
        Select Case True
            Case Weekday(fromDate, vbMonday) > 5
            Case DCount("*", "Holidays", "Holiday = #" & Format(fromDate, "mm/dd/yyyy") & "#") > 0
            Case Else: WorkingDays = WorkingDays + 1
        End Select
        fromDate = fromDate + 1
    Wend
End Function
Debra Triolo OP  @Reply  
     
17 months ago
And this is the event that calls on the module....
Private Sub Date_updated_in_System_AfterUpdate()
TAT = WorkingDays([Date_Returned], [Date_updated_in_System])
If Me.[Date_Returned] = Null Then Exit Sub
If Me.[Date_updated_in_System] = Null Then Exit Sub
Me.Refresh

End Sub
Richard Rost  @Reply  
          
17 months ago
You're on the right track. Instead of checking Nulls, I'd say:

If fromDate = toDate then...

Assuming your dates don't have times on them. If so, then:

If DateValue(fromDate) = DateValue(toDate) then...
Richard Rost  @Reply  
          
17 months ago
You can't send a Null value into a Date field parameter like that. It will throw an error. Only Variants can accept Null values.
Debra Triolo OP  @Reply  
     
17 months ago
@richard I actually made the change you suggested and it did give me a 0 TAT for anything completed same day. However, for items that have Dates that are not the same day... while it is running the function and properly excluding the weekend (and I am guessing holidays) from the count, it is not counting day 1 as 0, so the count is off by 1. Is there a way to have it count from 0 instead of 1. Example 3/7/2025  and 3/11/2025 is coming up with a TAT of 3, but I want it to come up as 2- since 3/7 is day 0, not 1. Hope this makes sense...
Richard Rost  @Reply  
          
17 months ago
I just finally took a look at the rest of your function. I was answering the other part of your question briefly before, but your Select Case statement is completely wrong. Why don't you use the MyNetWorkDays function from the Code Vault?
Debra Triolo OP  @Reply  
     
17 months ago
Regardless of which one I use, I still have the same issue. It is counting Day 1 as day 1, instead of day 0 when calculating the TAT for anything other than same day. How can I adjust the MyNetworkDays or the WorkingDays code to account for this or can it not be done?
Richard Rost  @Reply  
          
17 months ago
Can you not just subtract 1 from the final result?
Debra Triolo OP  @Reply  
     
17 months ago
If I try and adjust the TAT value then it throws it off for reports done same day (which has a TAT of 0). I guess I could try and do something like IF TAT >0 then - 1? and tack it onto to the after update event here:

Private Sub Date_updated_in_System_AfterUpdate()
TAT = WorkingDays([Date_Returned], [Date_updated_in_System])
If Me.[Date_Returned] = Null Then Exit Sub
If Me.[Date_updated_in_System] = Null Then Exit Sub
Me.Refresh

End Sub

??
Richard Rost  @Reply  
          
17 months ago
Not, it would be more like:

X = WorkingDays(Start, End)
If X > 0 then X = X - 1


Why all this checking for Null values?
Debra Triolo OP  @Reply  
     
17 months ago
The workingdays code was written that way by someone else. The TAT code I added that in because those fields are not always populated-sometimes only 1 of the fields is populated as the reports are being worked on. I needed a way to exit so that it did not bring up any errors or crash. A while ago I had posted here and got some advice on some errors...I think you had helped me on that as well.   I will try adding in what you posted. Thank you for helping me out. I feel like my brain is melting lately....
Richard Rost  @Reply  
          
17 months ago
I'm surprised it's not throwing an error. You normally need a variant in order for a function to receive a null value.
Debra Triolo OP  @Reply  
     
17 months ago
No, no errors at all. It is actually working beautifully now. Thank you so much for your help.
Richard Rost  @Reply  
          
17 months ago
You're very welcome. I do the best I can. Usually it's my moderators who get the praise because they answer a whole lot more questions than I do.

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: 8/7/2026 5:09:22 PM. PLT: 1s