The New keyword declares an instance of a report. Usage doesn't seem
consistent here where you have declared a variable named "myReport" to be an
instance of "rptD", and then opened "rptMyReport.Name", and allowed the
instance to go out of scope at the end of this procedure.
The specific error message indicates that you do not have a report named
"rptD", or that the report has no module.
Delete the declaration line that gives the error.
Change the OpenReprt line to:
DoCmd.OpenReport "rptMyReport", acViewPreview, , strFilter
You may also find it easier to use the IN operator rather than bucket loads
of "OR" phrases in the filter.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
"arthur-e" <ar*****@ix.netcom.com> wrote in message
news:lk********************************@4ax.com...
Hi
I'm trying to use a multiselect listbox to limit records in a report.
My version at work is 97 but now at home I'm using Access2002-
I know I can't go backwards ( to use this or similar code at work)
anyway:
msListBox - listnames unbound
report - rptD
Code is from the Microsoft Access 97 Developer's handbook
'PILastFirst' is the keyfield selected in the listbox - the bound
field from a query
rptD depends on
The button to view the report is has on the click event:
Private Sub btnPreviewReport_Click()
On Error GoTo Err_btnPreviewReport_Click
Dim vntItem As Variant, strFilter As String
Dim myReport As New Report_rptD
For Each vntItem In Me!ListNames.ItemsSelected
strFilter = strFilter & "[PILastFirst] = '" &
Me![ListNames].ItemData(vntItem) & "' OR "
Next
If strFilter <> "" Then
strFilter = Left(strFilter, Len(strFilter) - 4)
DoCmd.OpenReport rptMyReport.Name, acViewPreview, , strFilter
Else
MsgBox "no data has been selected!", vbOKOnly
End If
Exit_btnPreviewReport_Click:
Exit Sub
Err_btnPreviewReport_Click:
MsgBox Err.Description
Resume Exit_btnPreviewReport_Click
End Sub
-------------------
I get a "user-defined type not defined" message that refers to the
" Dim myReport As NEW Report_rptD " line
What is NEW that appears in the Dim statement?
THANKS in advance!!
-warning e-mail address altered- arthureNOSPACE@