T
Tony Williams
I have a form that the user chooses date parameters to run a report. The
code behind the OK button is
Private Sub cmdok_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\/yy\#"
strReport = "rptMainSenseCheck"
strField = "txtmonth"
If IsNull(Me.txtstartdate) Then
If Not IsNull(Me.txtenddate) Then 'End date, but no start.
strWhere = strField & " < " & Format(Me.txtenddate,
conDateFormat)
End If
Else
If IsNull(Me.txtenddate) Then 'Start date, but no End.
strWhere = strField & " > " & Format(Me.txtstartdate,
conDateFormat)
Else 'Both start and end dates.
strWhere = strField & " Between " & Format(Me.txtstartdate,
conDateFormat) _
& " And " & Format(Me.txtenddate, conDateFormat)
End If
End If
' Debug.Print strWhere 'For debugging purposes only.
DoCmd.OpenReport strReport, acViewPreview, , strWhere
End Sub
However I want them to also have the option of choosing another parameter
which will be a company name from a combo box called cmbselectcompany. The
combo box will be based on the control cmbCompany in a table tblcompany. Can
anyone help me with the additional code I need to add this choice. If the
user doesn't choose a company then I want the report to show all company's.
TIA
Tony Williams
code behind the OK button is
Private Sub cmdok_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\/yy\#"
strReport = "rptMainSenseCheck"
strField = "txtmonth"
If IsNull(Me.txtstartdate) Then
If Not IsNull(Me.txtenddate) Then 'End date, but no start.
strWhere = strField & " < " & Format(Me.txtenddate,
conDateFormat)
End If
Else
If IsNull(Me.txtenddate) Then 'Start date, but no End.
strWhere = strField & " > " & Format(Me.txtstartdate,
conDateFormat)
Else 'Both start and end dates.
strWhere = strField & " Between " & Format(Me.txtstartdate,
conDateFormat) _
& " And " & Format(Me.txtenddate, conDateFormat)
End If
End If
' Debug.Print strWhere 'For debugging purposes only.
DoCmd.OpenReport strReport, acViewPreview, , strWhere
End Sub
However I want them to also have the option of choosing another parameter
which will be a company name from a combo box called cmbselectcompany. The
combo box will be based on the control cmbCompany in a table tblcompany. Can
anyone help me with the additional code I need to add this choice. If the
user doesn't choose a company then I want the report to show all company's.
TIA
Tony Williams