A.D.TEJPAL
adtp at airtelbroadband.in
Wed Dec 13 23:24:22 CST 2006
Chester,
You won't need a separate function for getting DaysInMonth. Self contained sample subroutine as given below, should do.
Best wishes,
A.D.Tejpal
---------------
================================
Sub LoopFirstOfMonths(ByVal DtStart As Date, _
ByVal DtEnd As Date)
Dim Dte As Date
Dte = DtStart
Do While Dte <= DtEnd
Debug.Print Dte
Dte = DateAdd("m", 1, Dte)
Loop
End Sub
================================
----- Original Message -----
From: Kaup, Chester
To: Access Developers discussion and problem solving
Sent: Thursday, December 14, 2006 00:32
Subject: [AccessD] For next loop - using date criteria
I am trying to use date criteria in a for next loop but loop never
increments. Loop works if a hard code in a step but with variable. What might I be missing? Code below.
StartDate = #11/1/1948#
EndDate = #11/1/2006#
LoopStart = CLng(StartDate)
LoopEnd = CLng(EndDate)
For I = LoopStart To LoopEnd Step DaysinMonth
Debug.Print CVDate(I)
DaysinMonth = DaysInMonth2(CVDate(I)) + 1
Next I
End Function
Public Static Function DaysInMonth2(D As Date) As Integer
'
' Returns the number of days in a month
' Requires a date argument, since February can change if it's a leap
year
' Lets Access figure it out
'
If VarType(D) <> 7 Then
DaysInMonth2 = Null
Else
DaysInMonth2 = DateSerial(Year(D), Month(D) + 1, 1) -
DateSerial(Year(D), Month(D), 1)
End If
End Function
Chester Kaup