Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access report or Query?

Status
Not open for further replies.

davefish

Technical User
Jul 26, 2002
169
GB
Hi,

I'm new to access and what's it's capable of, but I wonder if anyone can help. In Excel I'm running a formula to ascertain the working days between two dates, eg, excluding weekends. I pull the data from access then use the =NETWORKINGDAYS function to get here. It would be a lot simpler if I can do it all in access, but I cannot find where to place a formulae that works, or in fact which formula to use for that matter.

Can anyone help??

DaveFish
 
So you have a custom function (that you coded) called NETWORKINGDAYS? You can put that code in an Access module...click on the Modules tab in Access and create a new one. I'm guessing this would need to be a function, so it will return a number.
Code:
Public Function NetWorkingDays(Date1 as Date, Date2 as Date) as Integer
   'calculate the days between date1 and date2, excluding weekends
   NetWorkingDays = YourAnswerGoesHere
End Function

Then save your module; and you will be able to call this from an Access query, or from code behind a form or report.

Good Luck!
 
Hi rjoubert,

The Networkingdays function is an Excel dervied one
=Networkdays(start_date,End_Date,holidays) it's not one I have coded. That being the case does you answer still stand?

DaveFish
 
Then you would need to create your own somehow. My answer will get you started, but you would need to write the logic within the function to arrive at your result. I'll do some more noodling on it, and if I come up with something, I'll let you know...
 
Try this out...
Code:
Public Function NetWorkingDays(StartDate As Date, EndDate As Date) As Integer

   Dim intCount As Integer

   intCount = 0

   Do While StartDate <= EndDate
      Select Case Weekday(StartDate)
         Case 1, 7
            intCount = intCount
         Case 2, 3, 4, 5, 6
            intCount = intCount + 1
      End Select
   
      StartDate = StartDate + 1
   Loop

   NetWorkingDays = intCount

End Function
[\code]

Note: This doesn't account for holidays.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top