G
Guest
I have entered the following VB to create date sort criteria.
Private Sub Command4_Click()
Dim strReport As String
Dim strField As String
Dim strWhere As String
Const conDateFormat = "\#dd\/mm\/yyyy\#"
strReport = "rptAllRecords"
strField = "PurchaseDate"
If IsNull(Me.txtStartDate) Then
If Not IsNull(Me.txtEndDate) Then
strWhere = strField & " <= " & Format(Me.txtEndDate, conDateFormat)
End If
Else
If IsNull(Me.txtEndDate) Then
strWhere = strField & " >= " & Format(Me.txtStartDate, conDateFormat)
Else
strWhere = strField & " Between " & Format(Me.txtStartDate,
conDateFormat) _
& " And " & Format(Me.txtEndDate, conDateFormat)
End If
End If
DoCmd.OpenReport strReport, acViewPreview, , strWhere
End Sub
However when this is run the report generated shows all the records, not
those between the date range selected.
The Report 'Properties' 'Data' 'Filter' shows the following:
(PurchaseDate Between #05/09/2004# And #10/09/2004#) or the equivilent for
other options.
The 'Filter On' criteria = 'yes'
Could anyone help please!
Many thanks
Private Sub Command4_Click()
Dim strReport As String
Dim strField As String
Dim strWhere As String
Const conDateFormat = "\#dd\/mm\/yyyy\#"
strReport = "rptAllRecords"
strField = "PurchaseDate"
If IsNull(Me.txtStartDate) Then
If Not IsNull(Me.txtEndDate) Then
strWhere = strField & " <= " & Format(Me.txtEndDate, conDateFormat)
End If
Else
If IsNull(Me.txtEndDate) Then
strWhere = strField & " >= " & Format(Me.txtStartDate, conDateFormat)
Else
strWhere = strField & " Between " & Format(Me.txtStartDate,
conDateFormat) _
& " And " & Format(Me.txtEndDate, conDateFormat)
End If
End If
DoCmd.OpenReport strReport, acViewPreview, , strWhere
End Sub
However when this is run the report generated shows all the records, not
those between the date range selected.
The Report 'Properties' 'Data' 'Filter' shows the following:
(PurchaseDate Between #05/09/2004# And #10/09/2004#) or the equivilent for
other options.
The 'Filter On' criteria = 'yes'
Could anyone help please!
Many thanks