Thanks, Steve, for your willingness to look at this. Yes, I am using
RunCode and have tried it with both the = and without it; no success there.
The Event I'm using to kick off the macro is On Load, for the form control
properties. Here is the VB code:
Option Compare Database
Function WorkingDays2(StartDate As Date, EndDate As Date) As Integer
'....................................................................
' Name: WorkingDays2
' Inputs: StartDate As Date
' EndDate As Date
' Returns: Integer
' Author: Arvin Meyer
' Date: May 5,2002
' Comment: Accepts two dates and returns the number of weekdays between them
' Note that this function has been modified to account for holidays. It
requires a table
' named tblHolidays with a field named HolidayDate.
'....................................................................
On Error GoTo Err_WorkingDays2
Dim intCount As Integer
'Dim rst As DAO.Recordset
'Dim DB As DAO.Database
Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT [HolidayDate] FROM tblHolidays",
dbOpenSnapshot)
'StartDate = StartDate + 1
'To count StartDate as the 1st day comment out the line above
intCount = 0
Do While StartDate <= EndDate
rst.FindFirst "[HolidayDate] = #" & StartDate & "#"
If Weekday(StartDate) <> vbSunday And Weekday(StartDate) <> vbSaturday Then
If rst.NoMatch Then intCount = intCount + 1
End If
StartDate = StartDate + 1
Loop
WorkingDays2 = intCount
Exit_WorkingDays2:
Exit Function
Err_WorkingDays2:
Select Case Err
Case Else
MsgBox Err.Description
Resume Exit_WorkingDays2
End Select
End Function
Thanks again.
Steve Schapel said:
Petey,
My guess is that you are using a RunCode action in your macro... Am I
right? If so, I think you need a = in front of the function name argument.
Apart from that, you will need to give more information. Since the
WorkingDays2() function is exclusive to your database, maybe you could
copy/paste the VBA code for this function into your return post, which
might help us to see what's happening. Also helpful to say what event
you are using to run this macro.
--
Steve Schapel, Microsoft Access MVP
PeteyP wrote:
Getting the 'type mismatch' error for this macro's function name action
argument and I don't know how to enter the requirements for defining dates,
although I have researched this as best I can. Can anyone help me out?
Thanks in advance.
The action argument is:
WorkingDays2([Forms]![TestForm1]![Val1],[Forms]![TestForm1]![PlanD1]-[Forms]![TestForm1]![ActD1])
The name of the macro is WorkingDays2.
The name of the module is WorkingDays.
The name of the Function is WorkingDays2. In it, I am calculating the
number of business days between two dates. Using the macro, I am attempting
to show the difference on a form in a control named Val1.