R
Ruth
I have a form format that I am using for a number of reports. Each
time I get it working (with help from folks on this forum!) the client
adds another parameter. :-/
The form filters a report.
Fields (combo boxes) on the form are:
cboStartDate
cboStopDate
cboCustName (CustID is the bound field but is not displayed in the
combo dropdown)
cboLocation
The trick here is that if any of the combo boxes don't have a
selection made, no filtering should be done on that selection.
I have tried to cobble together what I need from examples provided
online by Allen Browne. Unfortunately, I don't know what the heck I'm
doing, so I've probably made a mess of it. Here is the code (which
works through the between start date and end date part):
Private Sub PreviewCanceledJobsReport_Click()
On Error GoTo Err_PreviewCanceledJobsReport_Click
Dim strReport As String
Dim strField As String
Dim strWhere As String
Const conDateFormat = "\#mm\/dd\/yyyy\#"
strReport = "RptQryJobsCanceled"
strField = "Start"
If IsNull(Me.cboStartDate) Then
If Not IsNull(Me.cboStopDate) Then
strWhere = strField & " <= " & Format(Me.cboStopDate,
conDateFormat)
End If
Else
If IsNull(Me.cboStopDate) Then
strWhere = strField & " >= " & Format(Me.cboStartDate,
conDateFormat)
Else
strWhere = strField & " Between " & Format(Me.cboStartDate,
conDateFormat) _
& " And " & Format(Me.cboStopDate, conDateFormat) & " And "
End If
End If
If Not IsNull(Me.cboCustName) Then
strWhere = strWhere & "([CustomerID] = """ & _
Me![cboCustName].Value & """) AND "
End If
If Not IsNull(Me.cboLocation) Then
strWhere = strWhere & "([Location] = """ & _
Me![cboLocation].Value & """) AND "
End If
lngLen = Len(strWhere) - 5 'Without trailing " AND "
If lngLen > 0 Then
strWhere = Left$(strWhere, 5)
End If
' Debug.Print strWhere
If strWhere <> "" Then
DoCmd.OpenReport strReport, acViewPreview, , strWhere
DoCmd.Maximize
Else
DoCmd.OpenReport strReport, acViewPreview
DoCmd.Maximize
End If
Exit Sub
Err_PreviewCanceledJobsReport_Click:
MsgBox Err.Description
End Sub
================================================
Any help sorting this out will be appreciated!
Thanks,
Ruth
time I get it working (with help from folks on this forum!) the client
adds another parameter. :-/
The form filters a report.
Fields (combo boxes) on the form are:
cboStartDate
cboStopDate
cboCustName (CustID is the bound field but is not displayed in the
combo dropdown)
cboLocation
The trick here is that if any of the combo boxes don't have a
selection made, no filtering should be done on that selection.
I have tried to cobble together what I need from examples provided
online by Allen Browne. Unfortunately, I don't know what the heck I'm
doing, so I've probably made a mess of it. Here is the code (which
works through the between start date and end date part):
Private Sub PreviewCanceledJobsReport_Click()
On Error GoTo Err_PreviewCanceledJobsReport_Click
Dim strReport As String
Dim strField As String
Dim strWhere As String
Const conDateFormat = "\#mm\/dd\/yyyy\#"
strReport = "RptQryJobsCanceled"
strField = "Start"
If IsNull(Me.cboStartDate) Then
If Not IsNull(Me.cboStopDate) Then
strWhere = strField & " <= " & Format(Me.cboStopDate,
conDateFormat)
End If
Else
If IsNull(Me.cboStopDate) Then
strWhere = strField & " >= " & Format(Me.cboStartDate,
conDateFormat)
Else
strWhere = strField & " Between " & Format(Me.cboStartDate,
conDateFormat) _
& " And " & Format(Me.cboStopDate, conDateFormat) & " And "
End If
End If
If Not IsNull(Me.cboCustName) Then
strWhere = strWhere & "([CustomerID] = """ & _
Me![cboCustName].Value & """) AND "
End If
If Not IsNull(Me.cboLocation) Then
strWhere = strWhere & "([Location] = """ & _
Me![cboLocation].Value & """) AND "
End If
lngLen = Len(strWhere) - 5 'Without trailing " AND "
If lngLen > 0 Then
strWhere = Left$(strWhere, 5)
End If
' Debug.Print strWhere
If strWhere <> "" Then
DoCmd.OpenReport strReport, acViewPreview, , strWhere
DoCmd.Maximize
Else
DoCmd.OpenReport strReport, acViewPreview
DoCmd.Maximize
End If
Exit Sub
Err_PreviewCanceledJobsReport_Click:
MsgBox Err.Description
End Sub
================================================
Any help sorting this out will be appreciated!
Thanks,
Ruth