T
Tom
Hi,
I've scoured the forums for an answer to my question, but am wracking my
brain trying to get a Where Condition to work properly.
I want a report to print out records based upon a date range. I have a
button on a form which the user clicks that launches a "report format" form.
The user selects how they want the report to display: all records or a date
range - from the Report Format form. The "all" option works just fine. The
coding of the Where Condition seems to be the problem for the date range
option. The current code (below) opens a blank report that has *Error* where
the data should be. I've tried other varients of quotes placement and the
best I can get it to do is bring up dialog boxes that prompts the user to
enter start date and end date. If I do enter these dates, the report prints
just fine. However, the "Report Format" form and these dialog boxes are
redundant. I just want the "report format" form for entry of start and end
dates.
Thanks for your help!
<code>
Private Sub cmdGetReport_Click()
On Error GoTo Err_cmdGetReport_Click
Dim stDocName As String
stDocName = "Tom's Billable Hours"
If Me.grpRecord.Value = 1 Then
DoCmd.OpenReport stDocName, acViewPreview
ElseIf Me.grpRecord.Value = 2 Then
If IsNull(txtEnterStartDate.Value) Or IsNull(txtEnterEndDate.Value)
Then
MsgBox "You must enter both start and end dates."
DoCmd.GoToControl "txtEnterStartDate"
Exit Sub
Else
If txtEnterStartDate.Value > txtEnterEndDate.Value Then
MsgBox "End date must be greater than Start date."
DoCmd.GoToControl "txtEnterStartDate"
Exit Sub
Else
Me.Visible = False
End If
End If
Dim StartDate As Date
Dim EndDate As Date
StartDate = Me.txtEnterStartDate.Value
EndDate = Me.txtEnterEndDate.Value
DoCmd.OpenReport stDocName, acPreview, , "[Service Date] Between " &
StartDate & " And " & EndDate
End If
Exit_cmdGetReport_Click:
Exit Sub
Err_cmdGetReport_Click:
MsgBox Err.Description
Resume Exit_cmdGetReport_Click
End Sub
</code>
I've scoured the forums for an answer to my question, but am wracking my
brain trying to get a Where Condition to work properly.
I want a report to print out records based upon a date range. I have a
button on a form which the user clicks that launches a "report format" form.
The user selects how they want the report to display: all records or a date
range - from the Report Format form. The "all" option works just fine. The
coding of the Where Condition seems to be the problem for the date range
option. The current code (below) opens a blank report that has *Error* where
the data should be. I've tried other varients of quotes placement and the
best I can get it to do is bring up dialog boxes that prompts the user to
enter start date and end date. If I do enter these dates, the report prints
just fine. However, the "Report Format" form and these dialog boxes are
redundant. I just want the "report format" form for entry of start and end
dates.
Thanks for your help!
<code>
Private Sub cmdGetReport_Click()
On Error GoTo Err_cmdGetReport_Click
Dim stDocName As String
stDocName = "Tom's Billable Hours"
If Me.grpRecord.Value = 1 Then
DoCmd.OpenReport stDocName, acViewPreview
ElseIf Me.grpRecord.Value = 2 Then
If IsNull(txtEnterStartDate.Value) Or IsNull(txtEnterEndDate.Value)
Then
MsgBox "You must enter both start and end dates."
DoCmd.GoToControl "txtEnterStartDate"
Exit Sub
Else
If txtEnterStartDate.Value > txtEnterEndDate.Value Then
MsgBox "End date must be greater than Start date."
DoCmd.GoToControl "txtEnterStartDate"
Exit Sub
Else
Me.Visible = False
End If
End If
Dim StartDate As Date
Dim EndDate As Date
StartDate = Me.txtEnterStartDate.Value
EndDate = Me.txtEnterEndDate.Value
DoCmd.OpenReport stDocName, acPreview, , "[Service Date] Between " &
StartDate & " And " & EndDate
End If
Exit_cmdGetReport_Click:
Exit Sub
Err_cmdGetReport_Click:
MsgBox Err.Description
Resume Exit_cmdGetReport_Click
End Sub
</code>