473,378 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

MultiSelect Listbox trouble

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
3 3265
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
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
Why not just use DoCmd.OpenReport strReport? Doesn't look like the
MSLB is the issue at all...
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sally | last post by:
I have a simple multiselect listbox with a rowsorce of MemberID, MemberName, SendLetter. SendLetter is a Yes/No field. What is the code to set SendLetter to Yes when the user selects MemberName? I...
2
by: Sally | last post by:
In a simple multiselect listbox, what is the code to return an item's index when it is selected? Thanks! Sally
2
by: Cassie Pennington | last post by:
I am trying to write various items from a multiselect list box to an SQL statement to update a report, without success. SQL only appears to accept hard-coded data or control values from a form, not...
1
by: | last post by:
I am having trouble getting the procedure to use a Multiselect listbox in a report to work. I am using Access 2000. Here's the code. The error I get is QueryDef "User-defined type not...
2
by: Peder Y | last post by:
Anyone knows if there is some kind of property or function that will return the last selected/deselected item/index in a multiselect ListBox? SelectedIndex will point to first index in the...
1
by: Mike P | last post by:
How do I get the values selected from a multiselect listbox? Cheers, Mike *** Sent via Developersdex http://www.developersdex.com ***
2
by: ttime | last post by:
I've got a form that uses a multiselect listbox. When a user is selected from a combo box, values are populated into this listbox associated with that user. The problem is, if one person has say...
3
by: kaosyeti via AccessMonster.com | last post by:
hey... i have an unbound multiselect listbox on a form that i want to use to populate text boxes on that form. so if a user selects the 3rd item in a list of 20, how can i have that item show up...
5
by: martin DH | last post by:
Hello, The details are below, but I have a simple form (Form1) with two objects and a "search" command button. When the two objects are cascading combo boxes (the form creates the parameters for a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.