473,772 Members | 3,786 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 btnPreviewRepor t_Click()
On Error GoTo Err_btnPreviewR eport_Click

Dim vntItem As Variant, strFilter As String
Dim myReport As New Report_rptD

For Each vntItem In Me!ListNames.It emsSelected
strFilter = strFilter & "[PILastFirst] = '" &
Me![ListNames].ItemData(vntIt em) & "' OR "
Next
If strFilter <> "" Then
strFilter = Left(strFilter, Len(strFilter) - 4)
DoCmd.OpenRepor t rptMyReport.Nam e, acViewPreview, , strFilter
Else
MsgBox "no data has been selected!", vbOKOnly
End If
Exit_btnPreview Report_Click:
Exit Sub

Err_btnPreviewR eport_Click:
MsgBox Err.Description
Resume Exit_btnPreview Report_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 3291
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.Na me", 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.OpenRepor t "rptMyRepor t", 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.net com.com> wrote in message
news:lk******** *************** *********@4ax.c om...
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 btnPreviewRepor t_Click()
On Error GoTo Err_btnPreviewR eport_Click

Dim vntItem As Variant, strFilter As String
Dim myReport As New Report_rptD

For Each vntItem In Me!ListNames.It emsSelected
strFilter = strFilter & "[PILastFirst] = '" &
Me![ListNames].ItemData(vntIt em) & "' OR "
Next
If strFilter <> "" Then
strFilter = Left(strFilter, Len(strFilter) - 4)
DoCmd.OpenRepor t rptMyReport.Nam e, acViewPreview, , strFilter
Else
MsgBox "no data has been selected!", vbOKOnly
End If
Exit_btnPreview Report_Click:
Exit Sub

Err_btnPreviewR eport_Click:
MsgBox Err.Description
Resume Exit_btnPreview Report_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.Na me", 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.OpenRepo rt "rptMyRepor t", 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.OpenRepor t 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
6368
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 want to do this as the selections are being made not after-the-fact after all selections are made. Thanks! Sally
2
1921
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
3359
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 variable data. Any clues as to how I can write several items to an SQL statement from a multiselect listbox to update a report? Thanks in anticipation Cassie
1
1907
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 defined". Private Sub CmdReport_Click() On Error GoTo Err_CmdReport_Click Dim stDocName, stSQL, stWhat, stCriteria As String
2
7957
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 SelectedIndices collection, so this is a dead end. My solution so far is to override the mouse click and key pressed events. However, since arrow up/down seems to keep a record of the item that currently has focus somehow, I would believe this...
1
7129
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
1600
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 10 entries in the listbox, and selects the last 3-4, and the next user only has 2 entries, those last 3-4 rows are still highlighted in the listbox. This introduces null values into my code which is definitely not good. I've tried using...
3
3628
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 in a text box? then, how can i have a second selected item show up in a different text box, without affecting the 1st one? (lboxOptions, txtboxOptions0, txtboxOptions1, etc..) -- Greg Message posted via AccessMonster.com
5
4256
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 query - Query1), the query returns my results proper. But when the two objects are cascading combo-then-multiselect listbox (the perferred format in this case), the query always returns zero records. Tables: COMPILE (contains the records to be...
0
9620
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10104
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.