473,808 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple, MultiSelect Listboxs that run a Query on a Form

112 New Member
I am a newbie running Access 2003. A couple of weeks back a member named ADezil help me write a code that let a , MultiSelect Listboxs that run a Query on a Form (many thanks). I have used this code so much that I am trying to expand it to run off more then one list box. However I can’t get it to work. Original code is below.

Expand|Select|Wrap|Line Numbers
  1. Private Sub PhotoSearch1_Click()
  2. Dim strOr As String
  3. Dim strDoc As String
  4. Dim varSelect As Variant
  5. Dim ctl As Control
  6.  
  7. strDoc = "frmDescription"
  8.  
  9. Set ctl = Forms!frmPhotoKeywordSearch.Controls("list1")
  10.  
  11. For Each varSelect In ctl.ItemsSelected
  12.   strOr = strOr & "[Photo Keywords] Like '*" & ctl.ItemData(varSelect) & "*' OR "
  13. Next varSelect
  14.  
  15. '   lose the last ' OR '
  16. strOr = Left(strOr, Len(strOr) - 4)
  17.  
  18. DoCmd.OpenForm strDoc, acNormal, , strOr
  19. DoCmd.Close acForm, "frmPhotoKeywordSearch"
  20. End Sub
Here is what I have been trying but it is not working. "list1" is my first listbox and "list2" is the one I am trying to add. Bothe are Multiselect list boxes.

Expand|Select|Wrap|Line Numbers
  1. Private Sub PhotoSearch1_Click()
  2. Dim strOr As String
  3. Dim strDoc As String
  4. Dim varSelect As Variant
  5. Dim ctl As Control
  6.  
  7. strDoc = "frmDescription"
  8.  
  9. Set ctl = Forms!frmPhotoKeywordSearch.Controls("list1")
  10.  
  11. For Each varSelect In ctl.ItemsSelected
  12.   strOr = strOr & "[Photo Keywords] Like '*" & ctl.ItemData(varSelect) & "*' OR "
  13. Next varSelect
  14.  
  15. Set ctl = Forms!frmPhotoKeywordSearch.Controls("list2")
  16.  
  17. For Each varSelect In ctl.ItemsSelected
  18.   strOr = strOr & "[Photo Keywords] Like '*" & ctl.ItemData(varSelect) & "*' OR "
  19. Next varSelect
  20.  
  21. '   lose the last ' OR '
  22. strOr = Left(strOr, Len(strOr) - 4)
  23.  
  24. DoCmd.OpenForm strDoc, acNormal, , strOr
  25. DoCmd.Close acForm, "frmPhotoKeywordSearch"
  26. End Sub
Is this simple and I am missing something or really complicated? Any help would be great.

Thanks
Nov 13 '07 #1
1 1791
nico5038
3,080 Recognized Expert Specialist
The code looks OK, but I find it strange that you're selecting the same field from multiple listboxes.
Another thing that can cuase trouble is the limitation of the length of the string. When too long it might get truncated. Use a breakpoint and the F8 to single step through your code to see what string is build.

Nic;o)
Nov 16 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2574
by: DK | last post by:
Hello everybody ! I need little help from Your side. I have form called Form2, and ListBox called List 20. Property of List 20 allow multiple selection. Also I have query called Distribution as mail merge source.I need to control query Distribution to send letters to people selected in List 20. When I use List20 control without multiple selection everything is OK. Single letter is printed. Thank You in advance for Your help
1
1985
by: tod4 | last post by:
Hi, My problem: I have query with value klient and product. On my form Im using multiselect box as filter of klient value. Now I would like to use second multiselect on this form for product value selection but only for those value that are filtered by first multiselect. I dont know how to connect selected value klient from first multiselect and value product from query and make it source of multiselect 2. Maybe someone did it before...
3
1557
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 predefined in access. The reason for this is that I need to run a transfertext macro that uses the query as a table. I have put the selected items from the listbox into a control on the form. The where clause looks like 'BABY FOOD' Or 'AUTOMOTIVE' if you...
5
4258
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...
1
1877
by: synergy | last post by:
I have a similar problem to other posts but the answers have not worked for me. I have a command button on a form that runs a query. One field in the query has criteria from a list box on the form. It works fine until I change the multiselect property of the list box to Simple or Extended and then the query returns no data. Does someone have generic code that I can use? I don't know anything about VB or SQL so I need elementary...
3
2670
by: bbcrock | last post by:
Real quick question, can anyone point me to an article discussing how to use a listbox where the data comes from a lookup table to store multiple records in a child table? I created a form based on a select query that joins the parent and child records, but it's not an obvious solution. I'm sure it's easy though, any links?
6
4682
by: woodey2002 | last post by:
Hi Everyone. Thanks for your time. I am trying to create a search form that will allow users to select criteria from multiple multi select boxes. So far i have managed to achieve a search option for 2 list boxes:- county and nationality, while trying to add a third multi select list box for qualifications search is where i encounter my problem. I've copied the working code from my working list boxes, however it cant seem to pick up the...
1
6805
by: woodey2002 | last post by:
Hi Everyone and many thanks for your time.. I am trying to begin access and a bit of VBA i am enjoying it but I have a annoying problem I just can’t get any where on. My databse mostly includes bits of code for different examples. I have one last thing to finish. I am trying to create a search form that will allow users to select criteria from multiple sources eg ,multi select list boxes , combo boxes. I have a subform showing all the...
2
3045
by: hollinshead | last post by:
hi there, i have been having this issue for quite some time now and i cant seem to get my head around it. I am trying to create a database for candidates CV's and covering letters. basically the data that is stored is made up of qualifications and areas of business that candidate is involved etc. My problem is with the query by form where i have a range of combo boxes and list boxes. The combo boxes are working fine, no problem however the...
0
9721
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
10631
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10374
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10114
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9196
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...
1
7651
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6880
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();...
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3859
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.