PC Review


Reply
Thread Tools Rate Thread

Access 2003 using Excel NetWorkdays function

 
 
Don W
Guest
Posts: n/a
 
      22nd Feb 2009
The following code works in Office 12.0, but I'm using Office 11.0. Is there
some difference in the way that function must be called between the two
functions? The MsgBox does display the median (from
http://support.microsoft.com/?id=153748), but errors on the next line with
"Run-time error '438': Object doesn't support this property or method"

Public Function NetWorkdays(StartDate As Date, EndDate As Date) As Long
Dim obj As Excel.Application, WorkDays As Long
Set obj = CreateObject("Excel.Application")
WorkDays = obj.Application.NetWorkdays(StartDate, EndDate, Holidays())
MsgBox obj.Application.Median(1, 2, 5, 8, 12, 13)
obj.Quit
Set obj = Nothing
NetWorkdays = WorkDays
End Function

Function Holidays() As Date()
Dim rs As Recordset, counter As Long
Set rs = CurrentDb.OpenRecordset("Holidays")
Dim hd(100) As Date
Do While rs.EOF = False
hd(counter) = rs("Holidate")
rs.MoveNext
counter = counter + 1
Loop
Holidays = hd
End Function


 
Reply With Quote
 
 
 
 
Don W
Guest
Posts: n/a
 
      22nd Feb 2009
Ooops, sorry for any confusion -- the code should be this (the median
function works and the error occurs on the following NetWorkdays function):

Public Function NetWorkdays(StartDate As Date, EndDate As Date) As Long
Dim obj As Excel.Application, WorkDays As Long
Set obj = CreateObject("Excel.Application")
MsgBox obj.Application.Median(1, 2, 5, 8, 12, 13)
WorkDays = obj.Application.NetWorkdays(StartDate, EndDate, Holidays())
obj.Quit
Set obj = Nothing
NetWorkdays = WorkDays
End Function

Function Holidays() As Date()
Dim rs As Recordset, counter As Long
Set rs = CurrentDb.OpenRecordset("Holidays")
Dim hd(100) As Date
Do While rs.EOF = False
hd(counter) = rs("Holidate")
rs.MoveNext
counter = counter + 1
Loop
Holidays = hd
End Function


 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      22nd Feb 2009
Don't bother going through Excel.

For the equivalent of the NetWorkdays function, see my September, 2004
"Access Answers" column in Pinnacle Publcation's "Smart Access" You can
download the column (and sample database) for free from
http://www.accessmvp.com/djsteele/SmartAccess.html

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



"Don W" <(E-Mail Removed)> wrote in message
news:216EC7C6-E6F6-49B0-AF3F-(E-Mail Removed)...
> Ooops, sorry for any confusion -- the code should be this (the median
> function works and the error occurs on the following NetWorkdays
> function):
>
> Public Function NetWorkdays(StartDate As Date, EndDate As Date) As Long
> Dim obj As Excel.Application, WorkDays As Long
> Set obj = CreateObject("Excel.Application")
> MsgBox obj.Application.Median(1, 2, 5, 8, 12, 13)
> WorkDays = obj.Application.NetWorkdays(StartDate, EndDate, Holidays())
> obj.Quit
> Set obj = Nothing
> NetWorkdays = WorkDays
> End Function
>
> Function Holidays() As Date()
> Dim rs As Recordset, counter As Long
> Set rs = CurrentDb.OpenRecordset("Holidays")
> Dim hd(100) As Date
> Do While rs.EOF = False
> hd(counter) = rs("Holidate")
> rs.MoveNext
> counter = counter + 1
> Loop
> Holidays = hd
> End Function
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Networkdays Function in Access 97 Nabiyah Edwards via AccessMonster.com Microsoft Access Queries 4 23rd May 2005 07:30 PM
Networkdays Function in Access 97 Nabiyah Edwards via AccessMonster.com Microsoft Access Queries 0 23rd May 2005 01:37 PM
Networkdays function in Access Joey Microsoft Access Queries 7 8th Apr 2004 11:30 AM
Networkdays Function in Access? Lauren Microsoft Access Queries 6 22nd Mar 2004 06:28 PM
Is there a NetWorkDays function in MS-Access Joe Vavra Microsoft Access 1 8th Aug 2003 06:56 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:44 PM.