473,406 Members | 2,343 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.

Multiple, MultiSelect Listboxs that run a Query on a Form

112 100+
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 1776
nico5038
3,080 Expert 2GB
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
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...
1
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...
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...
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...
1
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....
3
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...
6
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...
1
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...
2
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...
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...
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
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,...
0
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...
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
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.