error 3011 in case 4 only

  • Thread starter Thread starter allie357
  • Start date Start date
A

allie357

I havve a form that runs reports based on the check box selected. They
were working fine and the first 3 cases work just fine but I get error
3011 when I try to run the last report. (It says it cannot find the
object even though it is there.
Any help is greatly appreciated. Thanks.
Code:
--------------------------------------------------------------------------------

Option Compare Database
Option Explicit

Private Sub Cancel_Click()
' This code created by Command Button Wizard.
On Error GoTo Err_Cancel_Click

' Close form.
DoCmd.Close

Exit_Cancel_Click:
Exit Sub

Err_Cancel_Click:
MsgBox Err.Description
Resume Exit_Cancel_Click

End Sub

Private Sub CboRCName_AfterUpdate()
Me!cboDeptName.Requery
End Sub



Private Sub subClearFields()
CboRCName = Null
cboDeptName = Null
txtStartDate = Null
txtEndDate = Null
FraReport = Null

End Sub

Private Sub Clear_Click()
Call subClearFields
End Sub

Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click


DoCmd.Close

Exit_cmdClose_Click:
Exit Sub

Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click

End Sub



Private Sub FraReport_AfterUpdate()
' Disable RC and Department combo boxes if user selected Violator
Number of Times
' report.

Const conNumTimes = 4

If Me!FraReport.Value = conNumTimes Then
'Me!CboRCName.Enabled = False
Me!cboDeptName.Enabled = False
Else
'Me!CboRCName.Enabled = True
Me!cboDeptName.Enabled = True
End If

End Sub

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
Me.Visible = False
DoCmd.OpenReport "rpt_Violations by Department", _
acViewPreview, , strWhere

Case 2
Me.Visible = False
DoCmd.OpenReport "rpt_Violations_by_Type", _
acViewPreview, , strWhere
Case 3
Me.Visible = False
DoCmd.OpenReport "rpt_Violations_by_Violator", _
acViewPreview, , strWhere

Case 4
Me.Visible = False
DoCmd.OpenReport "rpt_Violations_by_Violator_by Number of
Times", _
acViewPreview, strWhere
End Select

End Sub
 
I note that in all cases except case 4 you have used underscore
characters to separate the words. In Case 4 you use either an
underscore or a space. Have you double-checked the name of the report?

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================

I havve a form that runs reports based on the check box selected. They
were working fine and the first 3 cases work just fine but I get error
3011 when I try to run the last report. (It says it cannot find the
object even though it is there.
Any help is greatly appreciated. Thanks.
Code:
--------------------------------------------------------------------------------

Option Compare Database
Option Explicit

Private Sub Cancel_Click()
' This code created by Command Button Wizard.
On Error GoTo Err_Cancel_Click

' Close form.
DoCmd.Close

Exit_Cancel_Click:
Exit Sub

Err_Cancel_Click:
MsgBox Err.Description
Resume Exit_Cancel_Click

End Sub

Private Sub CboRCName_AfterUpdate()
Me!cboDeptName.Requery
End Sub



Private Sub subClearFields()
CboRCName = Null
cboDeptName = Null
txtStartDate = Null
txtEndDate = Null
FraReport = Null

End Sub

Private Sub Clear_Click()
Call subClearFields
End Sub

Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click


DoCmd.Close

Exit_cmdClose_Click:
Exit Sub

Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click

End Sub



Private Sub FraReport_AfterUpdate()
' Disable RC and Department combo boxes if user selected Violator
Number of Times
' report.

Const conNumTimes = 4

If Me!FraReport.Value = conNumTimes Then
'Me!CboRCName.Enabled = False
Me!cboDeptName.Enabled = False
Else
'Me!CboRCName.Enabled = True
Me!cboDeptName.Enabled = True
End If

End Sub

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
Me.Visible = False
DoCmd.OpenReport "rpt_Violations by Department", _
acViewPreview, , strWhere

Case 2
Me.Visible = False
DoCmd.OpenReport "rpt_Violations_by_Type", _
acViewPreview, , strWhere
Case 3
Me.Visible = False
DoCmd.OpenReport "rpt_Violations_by_Violator", _
acViewPreview, , strWhere

Case 4
Me.Visible = False
DoCmd.OpenReport "rpt_Violations_by_Violator_by Number of
Times", _
acViewPreview, strWhere
End Select

End Sub
 
Back
Top