473,406 Members | 2,208 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,406 software developers and data experts.

Can't get Multiselect listbox code to work for report

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
Dim varItem As Variant
Dim qdfTemp As QueryDef

stWhat = ""
stCriteria = ","

For Each varItem In Me!List1.ItemsSelected
stWhat = stWhat & "'" & Me!List1.ItemData(varItem) & "'"
stWhat = stWhat & stCriteria
Next varItem

Me!HiddenTextBox = CStr(Left$(stWhat, Len(stWhat) -
Len(stCriteria)))
Set qdfTemp = CurrentDb.QueryDefs("qryInventory")
stSQL = "SELECT Position, Line, Station, Status "
stSQL = stSQL & "FROM tblInventory WHERE Position"
stSQL = stSQL & " IN (" & Me!HiddenTextBox & ")"
qdfTemp.SQL = stSQL
qdfTemp.Close

stDocName = "tblInventory"

DoCmd.OpenReport stDocName, acPreview, qryInventory
Exit_CmdReport_Click:
Exit Sub

Err_CmdReport_Click:
MsgBox Err.Description
Resume Exit_CmdReport_Click

End Sub

Please advise and thanks, much!!

Bill Walsh
Nov 13 '05 #1
1 1892
wa********@sbcglobal.net wrote:
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
Dim varItem As Variant
Dim qdfTemp As QueryDef

stWhat = ""
stCriteria = ","

For Each varItem In Me!List1.ItemsSelected
stWhat = stWhat & "'" & Me!List1.ItemData(varItem) & "'"
stWhat = stWhat & stCriteria
Next varItem

Me!HiddenTextBox = CStr(Left$(stWhat, Len(stWhat) -
Len(stCriteria)))
Set qdfTemp = CurrentDb.QueryDefs("qryInventory")
stSQL = "SELECT Position, Line, Station, Status "
stSQL = stSQL & "FROM tblInventory WHERE Position"
stSQL = stSQL & " IN (" & Me!HiddenTextBox & ")"
qdfTemp.SQL = stSQL
qdfTemp.Close

stDocName = "tblInventory"

DoCmd.OpenReport stDocName, acPreview, qryInventory
Exit_CmdReport_Click:
Exit Sub

Err_CmdReport_Click:
MsgBox Err.Description
Resume Exit_CmdReport_Click

End Sub

Please advise and thanks, much!!

Bill Walsh

It might help if you put in a comma between each element.
Example
stWhat = stWhat & stCriteria & ", "
and at the end of adding elements, remove the comma and space.

Hint: When you have created a SQL string that fails, enter
Debug.Print yourSQLStringVariable
Then run, then go into the Debug/Immediate window and copy the SQL
string. Open a new query in design mode, don't add any tables, and go
into SQL view. Paste the SQL into the window and try to run. Your
error will most likely be very evident.
Nov 13 '05 #2

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

Similar topics

3
by: louise | last post by:
hi i am trying to set up a mail merge button which takes records from a multi-select listbox (the contents of which are decided by a query created by a search from) and not from a specific...
0
by: Peder Y | last post by:
I'm making an ownerdrawn multiselect multiextended ListBox where I'm calling the DrawItem event in my code on specific events and need to make my own DrawItemEventArgs. However, when do I need to...
6
by: ¿ Mahesh Kumar | last post by:
Hi groups, Control name : ListboxID (lstCertification), selection mode=mutliselect. On Pageload i'm assinging string lstSplit="1/3/6/8" of the previously selected listindex id's. Now on the...
3
by: ML | last post by:
I have used Allen Brown's technique for filling a listbox on a form with the names of files in a certain disc folder. It works well. I am now giving the user the option to print the form...
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...
1
by: IMK | last post by:
Hello all, Sorry if this issue has come up already but I am new to vb.net. Thanks. I am trying to retrieve the selectedvalues from a multiselect list box in a vb 2005 winform. Here is the code...
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...
3
by: jschmidt | last post by:
Hello Everyone, I have an access application that has a listbox on a form. The list box is set to multiselect. I want to be able to use the selected items in a parameterized query that is...
1
by: asharma0001 | last post by:
Hi all, I was wondering whether somebody might be able to help me with a question I have on a MS Access Database I'm building. I have created a search form with a few multiselect listboxes....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.