A
A Moloney
Hi
I have a sub form that pops up asking users to select two
dates (date range: will print all records that are
detailed between these dates) using teh below code. If i
do not enter any dates teh report correctly shows all
records but in the event that one or even two dates are
entered, it advises that the method or data member could
not be found. The following is my code, any advice
greatly appreciated;
Private Sub OK_Click()
Dim strPrintreport As String 'Name of report to open.
Dim strDate As String 'Name of your date field.
Dim strWhere As String 'Where condition for
OpenReport.
Const conDateFormat = "\#dd\/mmm\/yy\#"
strReport = "Printreport"
strField = "Date"
If IsNull(Me.txtStartDate) Then
If Not IsNull(Me.txtEndDate) Then 'End date,
but no start.
strWhere = strDate & " < " & Format
(Me.txtEndDate, conDateFormat)
End If
Else
If IsNull(Me.txtEndDate) Then 'Start date,
but no End.
strWhere = strDate & " > " & Format
(Me.txtStartDate, conDateFormat)
Else 'Both start
and end dates.
strWhere = strDate & " Between " & Format
(Me.txtStartDate, conDateFormat) _
& " And " & Format(Me.txtEndDate,
conDateFormat)
End If
End If
' Debug.Print strWhere 'For
debugging purposes only.
DoCmd.OpenPrintreport strPrintreport,
acViewPreview, , strWhere
End Sub
I have a sub form that pops up asking users to select two
dates (date range: will print all records that are
detailed between these dates) using teh below code. If i
do not enter any dates teh report correctly shows all
records but in the event that one or even two dates are
entered, it advises that the method or data member could
not be found. The following is my code, any advice
greatly appreciated;
Private Sub OK_Click()
Dim strPrintreport As String 'Name of report to open.
Dim strDate As String 'Name of your date field.
Dim strWhere As String 'Where condition for
OpenReport.
Const conDateFormat = "\#dd\/mmm\/yy\#"
strReport = "Printreport"
strField = "Date"
If IsNull(Me.txtStartDate) Then
If Not IsNull(Me.txtEndDate) Then 'End date,
but no start.
strWhere = strDate & " < " & Format
(Me.txtEndDate, conDateFormat)
End If
Else
If IsNull(Me.txtEndDate) Then 'Start date,
but no End.
strWhere = strDate & " > " & Format
(Me.txtStartDate, conDateFormat)
Else 'Both start
and end dates.
strWhere = strDate & " Between " & Format
(Me.txtStartDate, conDateFormat) _
& " And " & Format(Me.txtEndDate,
conDateFormat)
End If
End If
' Debug.Print strWhere 'For
debugging purposes only.
DoCmd.OpenPrintreport strPrintreport,
acViewPreview, , strWhere
End Sub