Yes, I thought you might be doing somehing like that.
The simplest workaround would be to let the user specify full dates, e.g.
July 1 2005 to October 31 2005. You could then use the code in this link:
http://allenbrowne.com/casu-08.html
If you don't want to do that, and you want to include October, you will need
to ask for less than November so all the October dates are included. The
most efficient approach would be to convert those text boxes into true
dates, so that Access can use any index on your date field and perform a
numeric date comparison. You will then need to format the date into the
correctly delimited format in the WhereCondition string:
Dim strWhere As String
Dim bCancel As Boolean
Const conJetDate = "\#mm\/dd\/yyyy\#"
If IsDate(BeginDate) And IsDate(EndDate) Then
If CDate(EndDate) < CDate(BeginDate) Then
MsgBox "The ending date must be later than the beginning date."
bCancel = True
End If
Else
MsgBox "Please use a valid date"
bCancel = True
End If
If Not bCancel Then
strWhere = "([MyDateField] >= " & _
Format(CDate(Me.BeginDate, conJetDate) & _
") AND ([MyDateField] < " & _
Format(CDate(Me.BeginDate, conJetDate) & ")"
'Debug.Print strWhere
DoCmd.OpenReport "MyReport", acViewPreview, , strWhere
End If
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
JOM said:
Thanks for your response, When I tried to open the report based on those
months (from July to September) it opened the report for may june july
september and october...
This is how my report is based..
my table has the following: Rcvddate e.g., 10/10/2005
so my report is grouped as follows:
RcvdMonths:Format$([RcvdDate],"mmmm yyyy",0,0) e.g., October 2005
so what could have I done wrong
Allen Browne said:
Try using CDate() to convert the entries to actual date values:
If IsDate(BeginDate) And IsDate(EndDate) Then
If CDate(EndDate) < CDate(BeginDate) Then
MsgBox "The ending date must be later than the beginning
date."
Exit Sub
End If
Else
MsgBox "Please use a valid date"
End If
I would like to Check to see that ending month is later than beginning
month.
How do I do that. because what I have is Checking to see if the
ending
date is later than beginning date as follows: (where begindate and
enddate
are unbound textboxes on a form now my form has 2 unbound textboxes
with
beginMonth and EndMonth. Months are formated as "mmmm yyyy" )
If IsDate(BeginDate) And IsDate(EndDate) Then
If EndDate < BeginDate Then
MsgBox "The ending date must be later than the beginning
date."
Exit Sub
End If
Else
MsgBox "Please use a valid date for the beginning date and the
ending date values."
End If