Function "Workingdays" query error date

G

Guest

I am trying to calculate the number of days, excluding weekends, between two
dates. I am using the "workingdays" VBA code. I have pasted the code in a
module, naming it "mdlWorkingdays". The code is listed below along with a
sample of the data.
"mdlWorkingdays"
Option Compare Database

'*********** Code Start **************
Public Function Workingdays(Start_Date As Date, End_Date As Date) As Integer
'....................................................................
' Name: WorkingDays
' Inputs: StartDate As Date
' EndDate As Date
' Returns: Integer
' Author: Arvin Meyer
' Date: February 19, 1997
' Comment: Accepts two dates and returns the number of weekdays between them
' Note that this function does not account for holidays.
'....................................................................
On Error GoTo Err_WorkingDays

Dim intCount As Integer

Start_Date = Start_Date + 1
'If you want to count the day of Start_Date as the 1st day
'Comment out the line above

intCount = 0
Do While Start_Date <= End_Date
'Make the above < and not <= to not count the End_Date

Select Case Weekday(Start_Date)
Case Is = 1, 7
intCount = intCount
Case Is = 2, 3, 4, 5, 6
intCount = intCount + 1
End Select
Start_Date = Start_Date + 1
Loop
Workingdays = intCount

Exit_WorkingDays:
Exit Function

Err_WorkingDays:
Select Case Err

Case Else
MsgBox Err.Description
Resume Exit_WorkingDays
End Select

End Function

Sample Data:
Start_Date End_Date
2/14/2006 2/20/2006
2/14/2006 2/21/2006
2/15/2006 2/15/2006
2/10/2006 2/10/2006

I have been trying to use the function in a query. Each time, I get the
following error: "Ambiguous name. in query
'Workingdays([Start_Date],[End_Date])'.
Any help in solving this problem would be greatly appreciated.
 
J

John W. Vinson

I have been trying to use the function in a query. Each time, I get the
following error: "Ambiguous name. in query
'Workingdays([Start_Date],[End_Date])'.

Please post the SQL of the query. I don't think it's a problem with the
function itself; perhaps you're naming the calculated field from Workingdays
with a name that you have already used in the query.

John W. Vinson [MVP]
 
G

Guest

I hope this helps.

SELECT Test_Dates.Start_Date, Test_Dates.End_Date,
Workingdays([Start_Date],[End_Date]) AS ContactDays
FROM Test_Dates;

Thank you for your reply.
Steve

John W. Vinson said:
I have been trying to use the function in a query. Each time, I get the
following error: "Ambiguous name. in query
'Workingdays([Start_Date],[End_Date])'.

Please post the SQL of the query. I don't think it's a problem with the
function itself; perhaps you're naming the calculated field from Workingdays
with a name that you have already used in the query.

John W. Vinson [MVP]
 
D

Douglas J. Steele

Do a search of your database. Access is saying that you've got more than one
function named Workingdays in your database.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Steve said:
I am trying to calculate the number of days, excluding weekends, between
two
dates. I am using the "workingdays" VBA code. I have pasted the code in
a
module, naming it "mdlWorkingdays". The code is listed below along with a
sample of the data.
"mdlWorkingdays"
I have been trying to use the function in a query. Each time, I get the
following error: "Ambiguous name. in query
'Workingdays([Start_Date],[End_Date])'.
Any help in solving this problem would be greatly appreciated.
 
J

John W. Vinson

Do a search of your database. Access is saying that you've got more than one
function named Workingdays in your database.

Ahhh.... that's almost surely it, Douglas. Thanks for the catch!

John W. Vinson [MVP]
 
G

Guest

Thank You. That was exactly the problem. I had that function in another
module of a different name. I thought that if the other module had a
different name, I could avoid any conflicts. I deleted the other module and
everything work fine. Thanks again, you have been a great help. I have
learned from your replies in the past, thanks

Douglas J. Steele said:
Do a search of your database. Access is saying that you've got more than one
function named Workingdays in your database.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Steve said:
I am trying to calculate the number of days, excluding weekends, between
two
dates. I am using the "workingdays" VBA code. I have pasted the code in
a
module, naming it "mdlWorkingdays". The code is listed below along with a
sample of the data.
"mdlWorkingdays"
I have been trying to use the function in a query. Each time, I get the
following error: "Ambiguous name. in query
'Workingdays([Start_Date],[End_Date])'.
Any help in solving this problem would be greatly appreciated.
 
G

Guest

Thank you for your help. Problem solved. I didn't expect anyone to reply
that quickly. I really appreciate it.
 

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

Similar Threads

Viewing Totals/GroupBy creates Data Mismatch 3
Calculating Rolling Usage 1
Custom Function 6
Calculate businness Days 1
Help with crosstab query 2
MDE File 4
#Error in Results 4
Dates in a date range 2

Top