472,785 Members | 1,168 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,785 software developers and data experts.

Search form multiple multi select list box's Error

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 [tblQualifications].[QualCode], [tblQualifications].[ShortQual] FROM tblQualifications 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()
  3.     ' Update the record source
  4.     'Me.sbfrmSearchResults1.Form.RecordSource = "SELECT * FROM qryNew " & BuildFilter
  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
  13.     'Requery the subform
  14.     Me.sbfrmSearchResults1.Requery
  17. End Sub
  20. Private Function BuildFilter() As Variant
  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
  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
  35.     ' Check for LIKE First Name
  36.     If Me.txtFirstName > "" Then
  37.         varWhere = varWhere & "[FirstName] LIKE """ & Me.txtFirstName & "*"" AND "
  38.     End If
  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
  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
  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
  66.         'Add some parentheses around the subfilter
  67.         varWhere = varWhere & "( " & CountyCode & " ) AND "
  68.     End If
  71.   'NationalityCode
  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 "
  78.     Next
  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
  89.         'Add some parentheses around the subfilter
  90.         varWhere = varWhere & "( " & NationalityCode & " ) AND "
  91.     End If
  94.       'qualCode
  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 "
  101.     Next
  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
  112.         'Add some parentheses around the subfilter
  113.         varWhere = varWhere & "( " & qualCode & " )  "
  114.     End If
  118.      'Check if there is a filter to return...
  119.     If IsNull(varWhere) Then
  120.         varWhere = "''"
  121.     Else
  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
  128.     End If
  131.     BuildFilter = varWhere
  133.     End Function
Thanks again.
Attached Images
File Type: jpg Relationship screenshot.jpg (8.7 KB, 417 views)
Feb 25 '09 #1
6 4590
32,534 Expert Mod 16PB
I will only get involved as far as to suggest checking out Example Filtering on a Form.
Feb 25 '09 #2
8,834 Expert 8TB
  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
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 [tblqualifications]_[qualCode] i get a syntax error in query expression
'( [tblqualifications]_[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
[tblMemberDetails_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 tblMemberDetails where as the field for qualification is located in another table. i think i need to reference tblMemberQualifications.qualCode as opposed to tblQualifications.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, 1626 views)
Attached Files
File Type: zip James sample databse .zip (62.4 KB, 163 views)
Feb 25 '09 #4
8,834 Expert 8TB
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
675 512MB
If line 12 were Debug.Print Me.sbfrmSearchResults1.Form.RecordSource, 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
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.


Feb 26 '09 #7

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

Similar topics

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...
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...
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...
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...
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...
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...
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...
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...
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...
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.