R
Rob Parker
I'm trying to use the technique described in KB299016 to dynamically filter
a report prior to using SendObject. This includes the following
instruction:
<quote>
Set the OnOpen property of the report to the following event procedure:
Me.Filter = strFilter
<endquote>
(Well, actually, the KB article uses strInvoiceWhere, but I'm not dealing
with Invoices.)
strFilter is a Public string variable, defined in the code module for the
form containing my command button to run the SendObject code.
When I run the code, I get Error 2485 "Microsoft Access can't find the macro
'Me.'". If I change the entry in the OnOpen property to:
Filter = strFilter
I get Error 2485 "Microsoft Access can't find the macro 'Filter =
strFilter'".
A search of the Access newsgroups revealed KB209582, which includes this
error being generated by space characters in an event entry; however,
removing the spaces in the entry has no effect - I still get the same error.
Any fix/ideas/suggestions gladly received.
TIA,
Rob
PS. For completeness, my code (direct cut/paste) is as follows:
Option Compare Database
Option Explicit
Public strFilter As String
Private Sub cmdSnpReports_Click()
Dim rst As DAO.Recordset
Dim strSQL As String
On Error GoTo cmdSnpReports_Click_Error
strSQL = "SELECT DISTINCT PersonName FROM tblEmployeeReviews;"
Set rst = CurrentDb.OpenRecordset(strSQL)
rst.MoveFirst
Do While Not rst.EOF
strFilter = "PersonName = '" & rst!PersonName & "'"
DoCmd.SendObject acSendReport, "rptEmployeeReviews", acFormatSNP,
rst!PersonName
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
ExitPoint:
Exit Sub
cmdSnpReports_Click_Error:
Select Case Err.Number
Case 2501
Resume Next
Case Else
MsgBox "Error " & Err.Number & " (" & Err.Description & ")" &
vbNewLine _
& "in procedure cmdSnpReports_Click" & vbNewLine _
& "of VBA Document Form_frmVariousActions"
End Select
Resume ExitPoint
Resume 'set this line as next statement, when debugging after Ctrl-Brk,
to find error line
End Sub
a report prior to using SendObject. This includes the following
instruction:
<quote>
Set the OnOpen property of the report to the following event procedure:
Me.Filter = strFilter
<endquote>
(Well, actually, the KB article uses strInvoiceWhere, but I'm not dealing
with Invoices.)
strFilter is a Public string variable, defined in the code module for the
form containing my command button to run the SendObject code.
When I run the code, I get Error 2485 "Microsoft Access can't find the macro
'Me.'". If I change the entry in the OnOpen property to:
Filter = strFilter
I get Error 2485 "Microsoft Access can't find the macro 'Filter =
strFilter'".
A search of the Access newsgroups revealed KB209582, which includes this
error being generated by space characters in an event entry; however,
removing the spaces in the entry has no effect - I still get the same error.
Any fix/ideas/suggestions gladly received.
TIA,
Rob
PS. For completeness, my code (direct cut/paste) is as follows:
Option Compare Database
Option Explicit
Public strFilter As String
Private Sub cmdSnpReports_Click()
Dim rst As DAO.Recordset
Dim strSQL As String
On Error GoTo cmdSnpReports_Click_Error
strSQL = "SELECT DISTINCT PersonName FROM tblEmployeeReviews;"
Set rst = CurrentDb.OpenRecordset(strSQL)
rst.MoveFirst
Do While Not rst.EOF
strFilter = "PersonName = '" & rst!PersonName & "'"
DoCmd.SendObject acSendReport, "rptEmployeeReviews", acFormatSNP,
rst!PersonName
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
ExitPoint:
Exit Sub
cmdSnpReports_Click_Error:
Select Case Err.Number
Case 2501
Resume Next
Case Else
MsgBox "Error " & Err.Number & " (" & Err.Description & ")" &
vbNewLine _
& "in procedure cmdSnpReports_Click" & vbNewLine _
& "of VBA Document Form_frmVariousActions"
End Select
Resume ExitPoint
Resume 'set this line as next statement, when debugging after Ctrl-Brk,
to find error line
End Sub