Autoeng
Why me?
- Local time
- Today, 16:41
- Joined
- Aug 13, 2002
- Messages
- 1,302
Found this on another site as to how to use NETWORKDAYS in Access.
There is a NetWorkDays function available to Excel worksheets but not directly available in Microsoft Access. You may have noticed that this function is listed in Microsoft Access help. This
is because we included the Excel help topics in case users were using the Excel spreadsheet components within Data Access Pages in Access 2000.
In any case, the NetWorkDays function is exposed in the Microsoft Office WebComponents function library (MSOWCF.Dll), and it is possible to reference this library from Microsoft Access and call this function indirectly by using your own function.
In order to use this particular function, follow these steps:
1. Insert a new module into your Microsoft Access database.
2. On the Tools menu, click References.
3. Scroll down through the list, and check the checkbox next to "Microsoft Office Web Components Function Library." If it is not in the list, then click the Browse button, and locate MSOWCF.Dll
which should be in your C:\Program Files\Microsoft Office\Office folder.
4. Click OK to close the References dialog box.
5. Insert the following code into the module you created in step 1.
Function GetNetWorkDays(startDate As Date, endDate As Date) As Integer
Dim objFunction As MSOWCFLib.OCATP
Set objFunction = New MSOWCFLib.OCATP
GetNetWorkDays = objFunction.NETWORKDAYS(startDate, endDate)
Set objFunction = Nothing
End Function
This code allows you to indirectly call the NetWorkDays function from within Microsoft Access. You can call the GetNetWorkDays function, pass it the starting and ending dates, and then return the value from the NetWorkdays function.
If you want to call the function from a control on a Microsoft Access form or report, you would use the following syntax on the control's ControlSource property:
ControlSource: =GetNetWorkDays(#12/1/1999#, #12/17/1999#)
Of course, this example is using hard coded dates. You will need to replace the dates in the expression above with the dates you wish to calculate, or a reference to a field in your table which
contains them.
For instance, ControlSource: =GetNetWorkDays([StartDate], [EndDate])
There is a NetWorkDays function available to Excel worksheets but not directly available in Microsoft Access. You may have noticed that this function is listed in Microsoft Access help. This
is because we included the Excel help topics in case users were using the Excel spreadsheet components within Data Access Pages in Access 2000.
In any case, the NetWorkDays function is exposed in the Microsoft Office WebComponents function library (MSOWCF.Dll), and it is possible to reference this library from Microsoft Access and call this function indirectly by using your own function.
In order to use this particular function, follow these steps:
1. Insert a new module into your Microsoft Access database.
2. On the Tools menu, click References.
3. Scroll down through the list, and check the checkbox next to "Microsoft Office Web Components Function Library." If it is not in the list, then click the Browse button, and locate MSOWCF.Dll
which should be in your C:\Program Files\Microsoft Office\Office folder.
4. Click OK to close the References dialog box.
5. Insert the following code into the module you created in step 1.
Function GetNetWorkDays(startDate As Date, endDate As Date) As Integer
Dim objFunction As MSOWCFLib.OCATP
Set objFunction = New MSOWCFLib.OCATP
GetNetWorkDays = objFunction.NETWORKDAYS(startDate, endDate)
Set objFunction = Nothing
End Function
This code allows you to indirectly call the NetWorkDays function from within Microsoft Access. You can call the GetNetWorkDays function, pass it the starting and ending dates, and then return the value from the NetWorkdays function.
If you want to call the function from a control on a Microsoft Access form or report, you would use the following syntax on the control's ControlSource property:
ControlSource: =GetNetWorkDays(#12/1/1999#, #12/17/1999#)
Of course, this example is using hard coded dates. You will need to replace the dates in the expression above with the dates you wish to calculate, or a reference to a field in your table which
contains them.
For instance, ControlSource: =GetNetWorkDays([StartDate], [EndDate])
Last edited: