I suggest the following. As the 'run-time' of the report is within the month in whch the dates are that you wish to set, add some variable to the S.Q.L. e.g.
Dim sqlstrng as String, d1, d2 as Date
Add your code here for your algorithm as normal.....
d1 = Date
d2 = Date ' This sets d1 & d2 to the current system date i.e.today.
Do
If CByte(Val(Mid(Format(d1, "dd/mm/yyyy")), 2,1)) > 1 Then
GoTo 1
Else
' this repeatedly subtracts a day at a time from 'today's date until the first of the month is reached
d1 = d1 - 1
End If
Loop
Do
' likewise do the same for d2, only add one each time in the loop until the last day of the month is reached,(You may have to have further 'If' checks depending on whether there are 30, 31, 28, or 29 days in the current month)
Loop
sqlstrng = "SELECT (add fields, table etc.) FROM (add Table(s)) WHERE reportdates BETWEEN #" & d1 & "# AND #" & d2 & "#;"
I hope this helps. liamfitz.
|