A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Calculating workays between two dates



 
 
Thread Tools Display Modes
  #1  
Old September 6th, 2006, 11:22 AM posted to microsoft.public.access.forms
hotplate
external usenet poster
 
Posts: 55
Default Calculating workays between two dates

Hi,
I am using the first function on this website:
http://www.mvps.org/access/datetime/date0006.htm
Is there a way to keep from getting #error if one of the 2 dates are
missing? The user may fill in the closing date later.

Thanks,
James

  #2  
Old September 6th, 2006, 11:57 AM posted to microsoft.public.access.forms
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default Calculating workays between two dates

Change the parameters to Variants, rather than Dates, and check for Null
values in the code. I assume you want to return a 0 if they don't supply
both dates:

Public Function WorkingDays( _
StartDate As Variant, _
EndDate As Variant _
) As Integer
On Error GoTo Err_WorkingDays

Dim intCount As Integer

If IsNull(StartDate) Or _
IsNull(EndDate) Then
WorkingDays = 0
Else
StartDate = StartDate + 1

intCount = 0
Do While StartDate = EndDate

Select Case WeekDay(StartDate)
Case Is = 1, 7
intCount = intCount
Case Is = 2, 3, 4, 5, 6
intCount = intCount + 1
End Select
StartDate = StartDate + 1
Loop
WorkingDays = intCount
End If

Exit_WorkingDays:
Exit Function

Err_WorkingDays:
Select Case Err
Case Else
MsgBox Err.Description
Resume Exit_WorkingDays
End Select

End Function


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"hotplate" wrote in message
ups.com...
Hi,
I am using the first function on this website:
http://www.mvps.org/access/datetime/date0006.htm
Is there a way to keep from getting #error if one of the 2 dates are
missing? The user may fill in the closing date later.

Thanks,
James



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:50 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.