By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,829 Members | 673 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,829 IT Pros & Developers. It's quick & easy.

MultiSelect Listbox trouble

P: n/a
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@
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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@

Nov 12 '05 #2

P: n/a
As usual, Allen - you saved the day. Thank you.
I'm at a loss about the declaration of rptMyReport, though - since
that came directly from the text in the Microsoft Access 97 Developers
handbook.(p217)
I'm just a struggling amateur and will need to read up on the IN
operator.

"Allen Browne" <ab***************@bigpond.net.au> wrote:
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.

-warning e-mail address altered- arthureNOSPACE@
Nov 12 '05 #3

P: n/a
Why not just use DoCmd.OpenReport strReport? Doesn't look like the
MSLB is the issue at all...
Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.