Private Sub Preview_Click()
Dim strReport As String 'Name of report to open.
Dim strField As String 'Name of your date field.
Dim strWhere As String 'Where condition for OpenReport.
Const conDateFormat = "\#mm\/dd\/yyyy\#"
strReport = cboReportName
strField = "TransactionDate"
[COLOR="Red"]strWhere = "[SupplierID] = " & Me.cboSupplier & " AND "[/COLOR]
If IsNull(Me.BeginDate) Then
If Not IsNull(Me.EndDate) Then 'End date, but no start.
strWhere = strField & " <= " & Format(Me.EndDate, conDateFormat)
End If
Else
If IsNull(Me.EndDate) Then 'Start date, but no End.
strWhere = strField & " >= " & Format(Me.BeginDate, conDateFormat)
Else 'Both start and end dates.
strWhere = strField & " Between " & Format(Me.BeginDate, conDateFormat) _
& " And " & Format(Me.EndDate, conDateFormat)
End If
End If
' Debug.Print strWhere 'For debugging purposes only.
DoCmd.OpenReport strReport, acViewPreview, , strWhere
End Sub