Call a function in a query

N

NadSadBad

Hi,

I recently asked how you can calculate the number of days between 2 dates
without including weekends (Sat and Sun) in a query.

Someone came back and offered the following code and said i should call this
function:


Function DateDiffXWE(stDate As Date, fiDate As Date) As Integer
Dim nDays As Integer

nDays = 0
While stDate < fiDate
stDate = DateAdd("d", 1, stDate)
If Weekday(stDate) > 1 And Weekday(stDate) < 7 Then
nDays = nDays + 1
End If
Wend
DateDiffXWE = nDays
End Function

I am new to queries but wanted to know how you call this function in a query
and where exactly do i place the code..if u cant call it in a query, where
then do i call it from.

Any help would be greatly appreciated.

Thanks in advance
 
D

Dennis

I am the one who gave you this code. Create a column in your query like this
NoDays: DateDiffXWE([Date1],[Date2])

Date1 and Date2 should be the names of your date fields that you want to
calculate the difference between, excluding weekends.

The function DateDiffXWE can be copied and pasted into an existing module or
into a new module.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top