Count days with integer

G

Guest

Hi All
I’m trying to modify the famous weekday calculation from
http://www.mvps.org/access/datetime/date0006.htm

But I have a problem, I have a StartDate and I want to add ActiveDays
instead of an EndDate. But it returns nothing.

Public Function EndDate(StartDate As Date, ActiveDays As Integer) As Date
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)

intCount = 0

Do While intCount <= ActiveDays

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

End Function

Do anyone know what I have done wrong.

Thanks

Stefan
 
G

Guest

Thank you for your quick answer, Douglas.
But I’m not sure if I understand what you mean.

I have entered the following arguments in the function:

EndDate(“2005-03-01â€,â€3â€) (Swedish date)

But the results it giving me is 00:00:00

Thanks

Douglas J. Steele said:
You haven't assigned EndDate a value anywhere in your function.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Stefan said:
Hi All
I'm trying to modify the famous weekday calculation from
http://www.mvps.org/access/datetime/date0006.htm

But I have a problem, I have a StartDate and I want to add ActiveDays
instead of an EndDate. But it returns nothing.

Public Function EndDate(StartDate As Date, ActiveDays As Integer) As Date
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)

intCount = 0

Do While intCount <= ActiveDays

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

End Function

Do anyone know what I have done wrong.

Thanks

Stefan
 
R

Rob Oldfield

Given that it's a function called EndDate... you'll need, at some point, to
say EndDate=whatever to tell it what to return.


Stefan said:
Thank you for your quick answer, Douglas.
But I'm not sure if I understand what you mean.

I have entered the following arguments in the function:

EndDate("2005-03-01","3") (Swedish date)

But the results it giving me is 00:00:00

Thanks

Douglas J. Steele said:
You haven't assigned EndDate a value anywhere in your function.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Stefan said:
Hi All
I'm trying to modify the famous weekday calculation from
http://www.mvps.org/access/datetime/date0006.htm

But I have a problem, I have a StartDate and I want to add ActiveDays
instead of an EndDate. But it returns nothing.

Public Function EndDate(StartDate As Date, ActiveDays As Integer) As Date
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)

intCount = 0

Do While intCount <= ActiveDays

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

End Function

Do anyone know what I have done wrong.

Thanks

Stefan
 
G

Guest

Hi and thanks a lot for your answer Rob. I really appreciate the time and
help you are giving me.

I have changed my function to return an EndDate at the end. But why is
Access giving me the date 1900-01-03. If I give the argument
?EndDate("2005-03-01","3").

Why doesn’t it give me the “2005-03-04�

Public Function EndDate(StartDate As Date, ActiveDays As Integer) As Date
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)

intCount = 0

Do While intCount <= ActiveDays

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
EndDate = intCount

End Function

Best regards

Stefan


Rob Oldfield said:
Given that it's a function called EndDate... you'll need, at some point, to
say EndDate=whatever to tell it what to return.


Stefan said:
Thank you for your quick answer, Douglas.
But I'm not sure if I understand what you mean.

I have entered the following arguments in the function:

EndDate("2005-03-01","3") (Swedish date)

But the results it giving me is 00:00:00

Thanks

Douglas J. Steele said:
You haven't assigned EndDate a value anywhere in your function.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Hi All
I'm trying to modify the famous weekday calculation from
http://www.mvps.org/access/datetime/date0006.htm

But I have a problem, I have a StartDate and I want to add ActiveDays
instead of an EndDate. But it returns nothing.

Public Function EndDate(StartDate As Date, ActiveDays As Integer) As Date
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)

intCount = 0

Do While intCount <= ActiveDays

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

End Function

Do anyone know what I have done wrong.

Thanks

Stefan
 
D

Douglas J. Steele

Since intCount is an integer, it isn't going to give you an appropriate date
value. Based on your values, intCount is going to be 4 when the loop
finishes. Dates are actually 8 byte floating point numbers, where the
integer portion represents the date as the number of days relative to 30
Dec, 1899, and the decimal portion represents the time as a fraction of a
day. That's why you're getting 03 Jan 1900: it's 4 days from 30 Dec 1899.

I think what you want is EndDate = StartDate (since you've been incrementing
StartDate inside your loop)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Stefan said:
Hi and thanks a lot for your answer Rob. I really appreciate the time and
help you are giving me.

I have changed my function to return an EndDate at the end. But why is
Access giving me the date 1900-01-03. If I give the argument
?EndDate("2005-03-01","3").

Why doesn't it give me the "2005-03-04"?

Public Function EndDate(StartDate As Date, ActiveDays As Integer) As Date
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)

intCount = 0

Do While intCount <= ActiveDays

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
EndDate = intCount

End Function

Best regards

Stefan


Rob Oldfield said:
Given that it's a function called EndDate... you'll need, at some point,
to
say EndDate=whatever to tell it what to return.


Stefan said:
Thank you for your quick answer, Douglas.
But I'm not sure if I understand what you mean.

I have entered the following arguments in the function:

EndDate("2005-03-01","3") (Swedish date)

But the results it giving me is 00:00:00

Thanks

:

You haven't assigned EndDate a value anywhere in your function.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Hi All
I'm trying to modify the famous weekday calculation from
http://www.mvps.org/access/datetime/date0006.htm

But I have a problem, I have a StartDate and I want to add
ActiveDays
instead of an EndDate. But it returns nothing.

Public Function EndDate(StartDate As Date, ActiveDays As Integer)
As Date
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)

intCount = 0

Do While intCount <= ActiveDays

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

End Function

Do anyone know what I have done wrong.

Thanks

Stefan
 
M

Mike Painter

Stefan said:
I have changed my function to return an EndDate at the end. But why is
Access giving me the date 1900-01-03. If I give the argument
?EndDate("2005-03-01","3").

Why doesn't it give me the "2005-03-04"?

Public Function EndDate(StartDate As Date, ActiveDays As Integer) As
Date

You are returning EndDate as a Date.
Since Access starts at 1 Jan 100 it will take a rather large count to get
to 2005-03-04
 
G

Guest

Hi and a big thanks to Douglas and Rob for your help I really, really
appreciate your support. You are right – I changed the EndDate=StarDate and
it returns a date.

But why is Access returning the wrong date?

If I give the following arguments ?EndDate("2005-03-01","3"), Access is
giving me 2005-03-05 which is a Saturday. In the function I have excluded
Saturdays and Sundays.

Is something else wrong in the function or is Access pulling my legs?

Best regards

Stefan


Douglas J. Steele said:
Since intCount is an integer, it isn't going to give you an appropriate date
value. Based on your values, intCount is going to be 4 when the loop
finishes. Dates are actually 8 byte floating point numbers, where the
integer portion represents the date as the number of days relative to 30
Dec, 1899, and the decimal portion represents the time as a fraction of a
day. That's why you're getting 03 Jan 1900: it's 4 days from 30 Dec 1899.

I think what you want is EndDate = StartDate (since you've been incrementing
StartDate inside your loop)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Stefan said:
Hi and thanks a lot for your answer Rob. I really appreciate the time and
help you are giving me.

I have changed my function to return an EndDate at the end. But why is
Access giving me the date 1900-01-03. If I give the argument
?EndDate("2005-03-01","3").

Why doesn't it give me the "2005-03-04"?

Public Function EndDate(StartDate As Date, ActiveDays As Integer) As Date
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)

intCount = 0

Do While intCount <= ActiveDays

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
EndDate = intCount

End Function

Best regards

Stefan


Rob Oldfield said:
Given that it's a function called EndDate... you'll need, at some point,
to
say EndDate=whatever to tell it what to return.


Thank you for your quick answer, Douglas.
But I'm not sure if I understand what you mean.

I have entered the following arguments in the function:

EndDate("2005-03-01","3") (Swedish date)

But the results it giving me is 00:00:00

Thanks

:

You haven't assigned EndDate a value anywhere in your function.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Hi All
I'm trying to modify the famous weekday calculation from
http://www.mvps.org/access/datetime/date0006.htm

But I have a problem, I have a StartDate and I want to add
ActiveDays
instead of an EndDate. But it returns nothing.

Public Function EndDate(StartDate As Date, ActiveDays As Integer)
As
Date
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)

intCount = 0

Do While intCount <= ActiveDays

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

End Function

Do anyone know what I have done wrong.

Thanks

Stefan
 
R

Rob Parker

You do have an if statement that's checking for Saturday or Sunday, but you
are incrementing StartDate outside that If statement.

Rob

Stefan said:
Hi and a big thanks to Douglas and Rob for your help I really, really
appreciate your support. You are right - I changed the EndDate=StarDate and
it returns a date.

But why is Access returning the wrong date?

If I give the following arguments ?EndDate("2005-03-01","3"), Access is
giving me 2005-03-05 which is a Saturday. In the function I have excluded
Saturdays and Sundays.

Is something else wrong in the function or is Access pulling my legs?

Best regards

Stefan


Douglas J. Steele said:
Since intCount is an integer, it isn't going to give you an appropriate date
value. Based on your values, intCount is going to be 4 when the loop
finishes. Dates are actually 8 byte floating point numbers, where the
integer portion represents the date as the number of days relative to 30
Dec, 1899, and the decimal portion represents the time as a fraction of a
day. That's why you're getting 03 Jan 1900: it's 4 days from 30 Dec 1899.

I think what you want is EndDate = StartDate (since you've been incrementing
StartDate inside your loop)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Stefan said:
Hi and thanks a lot for your answer Rob. I really appreciate the time and
help you are giving me.

I have changed my function to return an EndDate at the end. But why is
Access giving me the date 1900-01-03. If I give the argument
?EndDate("2005-03-01","3").

Why doesn't it give me the "2005-03-04"?

Public Function EndDate(StartDate As Date, ActiveDays As Integer) As Date
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)

intCount = 0

Do While intCount <= ActiveDays

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
EndDate = intCount

End Function

Best regards

Stefan


:

Given that it's a function called EndDate... you'll need, at some point,
to
say EndDate=whatever to tell it what to return.


Thank you for your quick answer, Douglas.
But I'm not sure if I understand what you mean.

I have entered the following arguments in the function:

EndDate("2005-03-01","3") (Swedish date)

But the results it giving me is 00:00:00

Thanks

:

You haven't assigned EndDate a value anywhere in your function.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Hi All
I'm trying to modify the famous weekday calculation from
http://www.mvps.org/access/datetime/date0006.htm

But I have a problem, I have a StartDate and I want to add
ActiveDays
instead of an EndDate. But it returns nothing.

Public Function EndDate(StartDate As Date, ActiveDays As Integer)
As
Date
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)

intCount = 0

Do While intCount <= ActiveDays

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

End Function

Do anyone know what I have done wrong.

Thanks

Stefan
 
G

Guest

I’m sorry guys to ask again, but I had used the If –function in Excel a
million times and I used debug.print (here in Access) to get more information
about what could be wrong. But I’m still stuck.

If I use the StartDate in the if-statement I could have an endless loop.
Correct? Or???

I have changed every parameter in the function, but still I get a Saturday
if use ?EndDate("2005-03-01","3")

I feel stupid, but I probably can’t see straight for all the things I’ve
changed in the function.

What could be wrong?

Public Function EndDate(StartDate As Date, ActiveDays As Double) As Date
Dim intCount As Double
Dim rst As DAO.Recordset
Dim DB As DAO.Database

Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT [HolidayDate] FROM tblHolidays",
dbOpenSnapshot)

intCount = 0

Do While intCount <= ActiveDays

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
EndDate = StartDate
End Function

Best regards

Stefan


Rob Parker said:
You do have an if statement that's checking for Saturday or Sunday, but you
are incrementing StartDate outside that If statement.

Rob

Stefan said:
Hi and a big thanks to Douglas and Rob for your help I really, really
appreciate your support. You are right - I changed the EndDate=StarDate and
it returns a date.

But why is Access returning the wrong date?

If I give the following arguments ?EndDate("2005-03-01","3"), Access is
giving me 2005-03-05 which is a Saturday. In the function I have excluded
Saturdays and Sundays.

Is something else wrong in the function or is Access pulling my legs?

Best regards

Stefan


Douglas J. Steele said:
Since intCount is an integer, it isn't going to give you an appropriate date
value. Based on your values, intCount is going to be 4 when the loop
finishes. Dates are actually 8 byte floating point numbers, where the
integer portion represents the date as the number of days relative to 30
Dec, 1899, and the decimal portion represents the time as a fraction of a
day. That's why you're getting 03 Jan 1900: it's 4 days from 30 Dec 1899.

I think what you want is EndDate = StartDate (since you've been incrementing
StartDate inside your loop)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Hi and thanks a lot for your answer Rob. I really appreciate the time and
help you are giving me.

I have changed my function to return an EndDate at the end. But why is
Access giving me the date 1900-01-03. If I give the argument
?EndDate("2005-03-01","3").

Why doesn't it give me the "2005-03-04"?

Public Function EndDate(StartDate As Date, ActiveDays As Integer) As Date
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)

intCount = 0

Do While intCount <= ActiveDays

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
EndDate = intCount

End Function

Best regards

Stefan


:

Given that it's a function called EndDate... you'll need, at some point,
to
say EndDate=whatever to tell it what to return.


Thank you for your quick answer, Douglas.
But I'm not sure if I understand what you mean.

I have entered the following arguments in the function:

EndDate("2005-03-01","3") (Swedish date)

But the results it giving me is 00:00:00

Thanks

:

You haven't assigned EndDate a value anywhere in your function.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Hi All
I'm trying to modify the famous weekday calculation from
http://www.mvps.org/access/datetime/date0006.htm

But I have a problem, I have a StartDate and I want to add
ActiveDays
instead of an EndDate. But it returns nothing.

Public Function EndDate(StartDate As Date, ActiveDays As Integer)
As
Date
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)

intCount = 0

Do While intCount <= ActiveDays

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

End Function

Do anyone know what I have done wrong.

Thanks

Stefan
 
D

Douglas J. Steele

Try:

Do While intCount <= ActiveDays

If Weekday(StartDate) = vbSaturday Then
StartDate = StartDate + 2 ' Make it the next Monday
ElseIf Weekday(StartDate) <> vbSaturday Then
StartDate = StartDate + 1 ' Make it the next Monday
End If
rst.FindFirst "[HolidayDate] = #" & StartDate & "#"
If rst.NoMatch Then intCount = intCount + 1
StartDate = StartDate + 1

Loop

You might also want to check my September, 2004 Access Answer column in
Pinnacle Publication's Smart Access. You can download the article (and
accompanying database) free from
http://www.accessmvp.com/djsteele/SmartAccess.html

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Stefan said:
I'm sorry guys to ask again, but I had used the If -function in Excel a
million times and I used debug.print (here in Access) to get more
information
about what could be wrong. But I'm still stuck.

If I use the StartDate in the if-statement I could have an endless loop.
Correct? Or???

I have changed every parameter in the function, but still I get a Saturday
if use ?EndDate("2005-03-01","3")

I feel stupid, but I probably can't see straight for all the things I've
changed in the function.

What could be wrong?

Public Function EndDate(StartDate As Date, ActiveDays As Double) As Date
Dim intCount As Double
Dim rst As DAO.Recordset
Dim DB As DAO.Database

Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT [HolidayDate] FROM tblHolidays",
dbOpenSnapshot)

intCount = 0

Do While intCount <= ActiveDays

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
EndDate = StartDate
End Function

Best regards

Stefan


Rob Parker said:
You do have an if statement that's checking for Saturday or Sunday, but
you
are incrementing StartDate outside that If statement.

Rob

Stefan said:
Hi and a big thanks to Douglas and Rob for your help I really, really
appreciate your support. You are right - I changed the EndDate=StarDate and
it returns a date.

But why is Access returning the wrong date?

If I give the following arguments ?EndDate("2005-03-01","3"), Access is
giving me 2005-03-05 which is a Saturday. In the function I have
excluded
Saturdays and Sundays.

Is something else wrong in the function or is Access pulling my legs?

Best regards

Stefan


:

Since intCount is an integer, it isn't going to give you an
appropriate date
value. Based on your values, intCount is going to be 4 when the loop
finishes. Dates are actually 8 byte floating point numbers, where the
integer portion represents the date as the number of days relative to
30
Dec, 1899, and the decimal portion represents the time as a fraction
of a
day. That's why you're getting 03 Jan 1900: it's 4 days from 30 Dec 1899.

I think what you want is EndDate = StartDate (since you've been incrementing
StartDate inside your loop)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Hi and thanks a lot for your answer Rob. I really appreciate the
time and
help you are giving me.

I have changed my function to return an EndDate at the end. But why
is
Access giving me the date 1900-01-03. If I give the argument
?EndDate("2005-03-01","3").

Why doesn't it give me the "2005-03-04"?

Public Function EndDate(StartDate As Date, ActiveDays As Integer)
As Date
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)

intCount = 0

Do While intCount <= ActiveDays

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
EndDate = intCount

End Function

Best regards

Stefan


:

Given that it's a function called EndDate... you'll need, at some point,
to
say EndDate=whatever to tell it what to return.


Thank you for your quick answer, Douglas.
But I'm not sure if I understand what you mean.

I have entered the following arguments in the function:

EndDate("2005-03-01","3") (Swedish date)

But the results it giving me is 00:00:00

Thanks

:

You haven't assigned EndDate a value anywhere in your
function.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Hi All
I'm trying to modify the famous weekday calculation from
http://www.mvps.org/access/datetime/date0006.htm

But I have a problem, I have a StartDate and I want to add
ActiveDays
instead of an EndDate. But it returns nothing.

Public Function EndDate(StartDate As Date, ActiveDays As Integer)
As
Date
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)

intCount = 0

Do While intCount <= ActiveDays

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

End Function

Do anyone know what I have done wrong.

Thanks

Stefan
 

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