Problem with form and print preview of a report

A

allie357

I have a form that allows the user to run a variety of reports by using
a check box to select which to run.
The report runs but then I am unable to click on the print preview to
zoom in or click on it at all until I close the form. I need the form
to stay open. Any help is appreciated.


Code:
--------------------------------------------------------------------------------
Private Sub RunReport_Click()
On Error GoTo Err_Handler

Dim strRCName As String
Dim strDeptName As String
Dim strDate As String
Dim strWhere As String
Dim strWhereNumDate As String

strWhereNumDate = "DateEntered = Between
[Forms]![SummaryReportFilter1]![txtStartDate] And
[Forms]![SummaryReportFilter1]![txtEndDate]"

' Build criteria string for RCName field
If IsNull(Me.CboRCName.Value) Then
strRCName = "Like '*'"
Else
strRCName = "='" & Me.CboRCName.Value & "'"
End If
' Build criteria string for DeptName field
If IsNull(Me.cboDeptName.Value) Then
strDeptName = "Like '*'"
Else
strDeptName = "='" & Me.cboDeptName.Value & "'"
End If
' Build the WHERE clause.
strDate = "[DateEntered] Between #" & Me!txtStartDate & _
"# And #" & Me!txtEndDate & "#"
Err_Handler:
If Err.Number = 2501 Then
' ignore "action cancelled" error

Exit Sub

End If




' Combine criteria strings into a WHERE clause for the filter
strWhere = "[RCName] " & strRCName & " AND [DeptName] " &
strDeptName & " AND " & strDate
' Build criteria string for Report Type
Select Case Me.FraReport.Value
Case 1
DoCmd.OpenReport "rpt_Violations by Department", _
acViewPreview, , strWhere
Case 2
DoCmd.OpenReport "rpt_Violations_by_Type", _
acViewPreview, , strWhere
Case 3
DoCmd.OpenReport "rpt_Violations_by_Violator", _
acViewPreview, , strWhere
Case 4
DoCmd.OpenReport "rpt_Violations_by_Violator_by Number of
Times", _
acViewPreview, strWhere
End Select

End Sub
 
S

SteveS

Hi Allie,

I rewrote your code a little. Try this:

'------beg code--------------
Private Sub RunReport_Click()
On Error GoTo Err_Handler

Dim strWhere As String

'Build the WHERE clause

'Dates
If IsDate(Me.txtStartDate) _
And IsDate(Me.txtEndDate) _
And Me.txtStartDate < Me.txtEndDate Then

strWhere = "[DateEntered] Between #" & CDate(Me!txtStartDate) & _
"# And #" & CDate(Me!txtEndDate) & "# AND "
Else
MsgBox "Please check dates"
Exit Sub
End If

' RCName field
If Not IsNull(Me.CboRCName) Then
strWhere = strWhere & "[RCName] = '" & Me.CboRCName & "' AND "
End If

' DeptName field
If Not IsNull(Me.cboDeptName) Then
strWhere = strWhere & "[DeptName] = '" & Me.cboDeptName & "' AND "
End If

'remove the last 5 characters
strWhere = Left(strWhere, Len(strWhere) - 5)

'FOR DEBUGGING
MsgBox strWhere

Select Case Me.FraReport
Case 1
DoCmd.OpenReport "rpt_Violations by Department", _
acViewPreview, , strWhere
Case 2
DoCmd.OpenReport "rpt_Violations_by_Type", _
acViewPreview, , strWhere
Case 3
DoCmd.OpenReport "rpt_Violations_by_Violator", _
acViewPreview, , strWhere
Case 4
DoCmd.OpenReport "rpt_Violations_by_Violator_by Number of Times", _
acViewPreview, strWhere
End Select

Exit Sub

Err_Handler:
If Err.Number = 2501 Then
Resume Next
Else
MsgBox "ERROR " & Err.Number & " : " & Err.Description
End If

End Sub
'------end code-----------


If the report opend, you should be able to click on the report to zoom in
and out.

HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


allie357 said:
I have a form that allows the user to run a variety of reports by using
a check box to select which to run.
The report runs but then I am unable to click on the print preview to
zoom in or click on it at all until I close the form. I need the form
to stay open. Any help is appreciated.


Code:
--------------------------------------------------------------------------------
Private Sub RunReport_Click()
On Error GoTo Err_Handler

Dim strRCName As String
Dim strDeptName As String
Dim strDate As String
Dim strWhere As String
Dim strWhereNumDate As String

strWhereNumDate = "DateEntered = Between
[Forms]![SummaryReportFilter1]![txtStartDate] And
[Forms]![SummaryReportFilter1]![txtEndDate]"

' Build criteria string for RCName field
If IsNull(Me.CboRCName.Value) Then
strRCName = "Like '*'"
Else
strRCName = "='" & Me.CboRCName.Value & "'"
End If
' Build criteria string for DeptName field
If IsNull(Me.cboDeptName.Value) Then
strDeptName = "Like '*'"
Else
strDeptName = "='" & Me.cboDeptName.Value & "'"
End If
' Build the WHERE clause.
strDate = "[DateEntered] Between #" & Me!txtStartDate & _
"# And #" & Me!txtEndDate & "#"
Err_Handler:
If Err.Number = 2501 Then
' ignore "action cancelled" error

Exit Sub

End If




' Combine criteria strings into a WHERE clause for the filter
strWhere = "[RCName] " & strRCName & " AND [DeptName] " &
strDeptName & " AND " & strDate
' Build criteria string for Report Type
Select Case Me.FraReport.Value
Case 1
DoCmd.OpenReport "rpt_Violations by Department", _
acViewPreview, , strWhere
Case 2
DoCmd.OpenReport "rpt_Violations_by_Type", _
acViewPreview, , strWhere
Case 3
DoCmd.OpenReport "rpt_Violations_by_Violator", _
acViewPreview, , strWhere
Case 4
DoCmd.OpenReport "rpt_Violations_by_Violator_by Number of
Times", _
acViewPreview, strWhere
End Select

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top