473,890 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Search form multiple multi select list box's Error

15 New Member
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 search value from the qualification list box.

I think this error may stem from the relationships but i am not sure.

This is the record source property of one of my working list boxes:

lstNationality :SELECT [tblNationality].[NationalityCode], [tblNationality].[Nationality] FROM tblNationality;

This is the record source property of my new troublesom qualification list box:

SELECT [tblQualificatio ns].[QualCode], [tblQualificatio ns].[ShortQual] FROM tblQualificatio ns ORDER BY [ShortQual];

Am i correct in asuming that it's a relationship issue?

I have attached a screnshot of my relationships, and included a copy of my code in this post, if any body has any ideas they would be greatly appericated.
Many thanks once again for your time Kind regards, JAMES

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnSearch_Click()
  2.  
  3.     ' Update the record source
  4.     'Me.sbfrmSearchResults1.Form.RecordSource = "SELECT * FROM qryNew " & BuildFilter
  5.  
  6.     ' Update the record source
  7.     If BuildFilter = "" Then
  8.         Me.sbfrmSearchResults1.Form.RecordSource = "SELECT * FROM qryNew " & BuildFilter
  9.     Else
  10.         Me.sbfrmSearchResults1.Form.RecordSource = "SELECT * FROM qryNew WHERE " & BuildFilter
  11.     End If
  12.  
  13.     'Requery the subform
  14.     Me.sbfrmSearchResults1.Requery
  15.  
  16.  
  17. End Sub
  18.  
  19.  
  20. Private Function BuildFilter() As Variant
  21.  
  22.     Dim varWhere As Variant
  23.     Dim varItem As Variant
  24.     Dim intIndex As Integer
  25.     Dim CountyCode As Variant
  26.     Dim NationalityCode As Variant
  27.     Dim qualCode As Variant
  28.  
  29.     varWhere = Null  ' Main filter
  30.     CountyCode = Null  ' Subfilter used for CountyCode
  31.     NationalityCode = Null ' Subfilter used for NationalityCode
  32.     qualCode = Null ' Subfilter used for qualCode
  33.  
  34.  
  35.     ' Check for LIKE First Name
  36.     If Me.txtFirstName > "" Then
  37.         varWhere = varWhere & "[FirstName] LIKE """ & Me.txtFirstName & "*"" AND "
  38.     End If
  39.  
  40.     ' Check for LIKE Last Name
  41.     If Me.txtSurname > "" Then
  42.         varWhere = varWhere & "[surname] LIKE """ & Me.txtSurname & "*"" AND "
  43.     End If
  44.      ' Check for LIKE regNumber
  45.     If Me.txtRegNumber > "" Then
  46.         varWhere = varWhere & "[regnumber] like """ & Me.txtRegNumber & """  And "
  47.    End If
  48.  
  49.  
  50.  
  51.     ' Check for counties in multiselect list
  52.     For Each varItem In Me.lstCountyCode.ItemsSelected
  53.         CountyCode = CountyCode & " [tblMemberDetails_CountyCode] = """ & _
  54.                     Me.lstCountyCode.ItemData(varItem) & """ OR "
  55.          Next
  56.  
  57.     'Test to see if we have subfilter for colors...
  58.     If IsNull(CountyCode) Then
  59.         ' do nothing
  60.     Else
  61.         ' strip off last "OR" in the filter
  62.         If Right(CountyCode, 4) = " OR " Then
  63.             CountyCode = Left(CountyCode, Len(CountyCode) - 4)
  64.         End If
  65.  
  66.         'Add some parentheses around the subfilter
  67.         varWhere = varWhere & "( " & CountyCode & " ) AND "
  68.     End If
  69.  
  70.  
  71.   'NationalityCode
  72.  
  73.         ' Check for Nationality in multiselect list
  74.     For Each varItem In Me.lstNationality.ItemsSelected
  75.         NationalityCode = NationalityCode & " [tblmemberdetails.NationalityCode] = """ & _
  76.                     Me.lstNationality.ItemData(varItem) & """ OR "
  77.  
  78.     Next
  79.  
  80.     'Test to see if we have subfilter for colors...
  81.     If IsNull(NationalityCode) Then
  82.         ' do nothing
  83.     Else
  84.         ' strip off last "OR" in the filter
  85.         If Right(NationalityCode, 4) = " OR " Then
  86.             NationalityCode = Left(NationalityCode, Len(NationalityCode) - 4)
  87.         End If
  88.  
  89.         'Add some parentheses around the subfilter
  90.         varWhere = varWhere & "( " & NationalityCode & " ) AND "
  91.     End If
  92.  
  93.  
  94.       'qualCode
  95.  
  96.         ' Check for qualCode in multiselect list
  97.     For Each varItem In Me.lstqual1.ItemsSelected
  98.         qualCode = qualCode & " [tblqualifications_qualCode] = """ & _
  99.                     Me.lstqual1.ItemData(varItem) & """ OR "
  100.  
  101.     Next
  102.  
  103.     'Test to see if we have subfilter for colors...
  104.     If IsNull(qualCode) Then
  105.         ' do nothing
  106.     Else
  107.         ' strip off last "OR" in the filter
  108.         If Right(qualCode, 4) = " OR " Then
  109.             qualCode = Left(qualCode, Len(qualCode) - 4)
  110.         End If
  111.  
  112.         'Add some parentheses around the subfilter
  113.         varWhere = varWhere & "( " & qualCode & " )  "
  114.     End If
  115.  
  116.  
  117.  
  118.      'Check if there is a filter to return...
  119.     If IsNull(varWhere) Then
  120.         varWhere = "''"
  121.     Else
  122.  
  123.         ' strip off last "AND" in the filter
  124.         If Right(varWhere, 5) = " AND " Then
  125.             varWhere = Left(varWhere, Len(varWhere) - 5)
  126.         End If
  127.  
  128.     End If
  129.  
  130.  
  131.     BuildFilter = varWhere
  132.  
  133.     End Function
  134.  
Thanks again.
Attached Images
File Type: jpg Relationship screenshot.jpg (8.7 KB, 423 views)
Feb 25 '09 #1
6 4683
NeoPa
32,584 Recognized Expert Moderator MVP
I will only get involved as far as to suggest checking out Example Filtering on a Form.
Feb 25 '09 #2
ADezii
8,834 Recognized Expert Expert
  1. Could it be as smple as a Syntax Error, I am referring to Code Line #98
    Expand|Select|Wrap|Line Numbers
    1. 'Check for qualCode in multiselect list
    2. For Each varItem In Me.lstqual1.ItemsSelected
    3.   qualCode = qualCode & " [tblqualifications].[qualCode] = """ & _
    4.              Me.lstqual1.ItemData(varItem) & """ OR "
    5. Next
  2. You are treating the [qualCode] Field as if it were a String, is this Field, in fact, a String?
Feb 25 '09 #3
woodey2002
15 New Member
Thanks for the reply hugely appreciated.

I have tried your suggestion and its giving me a runtime error
"data type mismatch in criteria expression"

If i try [tblqualificatio ns]_[qualCode] i get a syntax error in query expression
'( [tblqualificatio ns]_[qualCode] = "3") this error seems somewhat correct because its recognising the qualCode from the listbox.

In answer to your question i am confident that its a string because the two working search options county and nationality seem to work following this principle.

Its strange because my code works for county search with
[tblMemberDetail s_CountyCode] where as my code for nationality search has to be [tblNationality. nationalityCode].

I dont know why this is but i am assuming that this might be giving me issues with qualification searching via the multi select list box.

having reviewed my database i discovered that the fields for my successful searches are stored in tblMemberDetail s where as the field for qualification is located in another table. i think i need to reference tblMemberQualif ications.qualCo de as opposed to tblQualificatio ns.qualCode but yet again i am not sure.

I have attached a sample version of my database, if anybody could have a look at it i would greatly appericate it as this is driving Me CRAZY.

Thanks again for all the support.

Regards James.
Attached Images
File Type: jpg james database relationship screenshot.jpg (12.5 KB, 1631 views)
Attached Files
File Type: zip James sample databse .zip (62.4 KB, 167 views)
Feb 25 '09 #4
ADezii
8,834 Recognized Expert Expert
@woodey2002
Right now, I'm on vacation and working with an older Version of Access (2000), which is essentially useless in this case. When I return home on Friday, and if this Thread has not yet been resolved, I'll have a good look at it and get back to you during the weekend.
Feb 26 '09 #5
OldBirdman
675 Contributor
If line 12 were Debug.Print Me.sbfrmSearchR esults1.Form.Re cordSource, you would have the actual SQL string used. If you paste that into the SQL window in query design, then switch to DataSheet view, what happens? Switching to Design view and looking at the grid, are there any obvious errors? Does removing some of the criteria get the results it should? This is one quick way to narrow the problem down, and you should quickly find the error.

If not, using the Design Query, design a new query which exactly mimics your problem. Enter the criteria that you are using in the various controls on your form. Switch to DataSheet view to be sure you got it right. Switch to SQL view and compare the generated SQL statement to the Debug.Print you inserted in line 12.
Feb 26 '09 #6
woodey2002
15 New Member
Hi
thanks for the responce.

I figured is out it was finally with some advice from my friend.

qualCode a numeric value in the table (the data type) so, i don't want quotes around the value.

Thanks so much for all the assistance.

All the best and thanks again.

Regards

JAMES.
Feb 26 '09 #7

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

Similar topics

4
9507
by: JSMiami | last post by:
I have a form that is fed by a certain table. This table connects to an intermeddiate table and then a look up table. All of this is done to accomplish a many-to-many relationship. Imagine that the form's table represents employees in a company and let's assume that an employee can belong to multiple departments. The lookup table mentioned above is represents the departments and the intermediate table represents the many-to-many...
2
5490
by: Sean | last post by:
Greetings all, I am attempting to make a form that will filter through several tables that (I believe) have refretial integrity. I am pulling data from several tables into the form and i would like to eventually be able to filter down through the tables untill i can reach one unique record. I am creating a datbase to keep track of registered accounts for a stae program. Each account is registered into the program through a two...
2
3048
by: google | last post by:
Hello everyone, I am having an issue using the "Multi Select" option in a list box in MS Access 2003. I am making a form that users can fill out to add an issue to the database. Each issue can be associated with multiple categories. I have an "Issue," "IssueCategory," and "Category" in the database (among other tables). The form has a subform in it which is tied to the "IssueCategory" table. The main form is tied to the "Issue"...
18
3358
by: Alpha | last post by:
Hi, I'm working on a Windows applicaton with VS 2003 on windows 2000. I have a listbox that I have binded to a dataset table, "source" which has 3 columns. I would like to display 2 of those columns, "scode" and "sname", as 1 column (if not possible then 2 columns will be fine) in the listbox. Can the listbox display 2 columns information from the dataset and how can I do that? Also, I set the property of the listbox to selectionmode...
6
9436
by: Dave | last post by:
On my form I have combo boxes. These combo boxes, after updating them, populate respective listboxes that are located below the combo boxes on the same form. I am trying to use a "generate report" button located on my form to print all of the list box values (that have been updated via selection from combo boxes) from the form to the report. I've tried using a macro with the code: Macro Name: cmdGenerateReport : On Click Action:...
1
4895
by: KrazyKasper | last post by:
Access 2003 – Multi-Column List Box – Select Multiple Items I have a multi-column (3 columns) list box that works well to select one set of records or all sets of records (based on the first field in the list box). I need to it also select multiple sets of records (Multi-Select = Extended). I modified my code based on code I found on some Internet site which gave an example using three fields in a three field table. It loops through the...
36
3277
by: aaronkmar | last post by:
Hello Bytes, I've been a long time lurker, there so much information here I always find my answers with ease. Until today... I'm hoping someone can exert a little brain power for me. I have a search form using the tried and true 'AddToWhere' module, this is working like a champ for user input text boxes but now I'm faced with integrating a multi-select listbox into the same routine. An added bit of difficulty is all of my code is on...
11
5614
by: woodey2002 | last post by:
This problem is driving me crazy. Hello there, i am trying to create a search form for records in my access database. The search form will contain text boxes and a multi select list box. The user can enter their search criteria eg. surname, reg num, etc. in the text boxes. The multi select list box allows the user to select multiple counties which they have the option of including in the search. The user should be able to select or omit the...
2
2757
by: woodey2002 | last post by:
Hi Guys and thanks for your time. I have a search form for my database that allows users to select multiple criteria from multi select list boxes. I successfully integrated a multi select listbox for users to select and search for counties. On the same page however I would like to integrate a similar multiselect box for nationality. I would like the user to be able to search for nationality with county or individually. After...
0
9976
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
9815
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
11215
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...
0
10802
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...
1
10908
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
9618
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
7160
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
5835
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...
1
4665
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

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.