473,385 Members | 1,587 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,385 software developers and data experts.

Multiple List boxes using QBF

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 multi select list boxes are the problem. I keep getting an error saying 'Data type Mismatch in criteria Expression'.

The structure of my database some would say is not the best way to go about it, as it is not fully normalised. However ive found that if i want to keep the same layout, displaying all the candidates data in list boxes and combo boxes then and using these features on the search form, then i am stuck with it.

The code i have used in the command button to start the filter process is displayed below. thanks for your time and efforts. Anyone got any ideas as to how i could get this resolved?
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSearchCriteria_Click()
  2.     Dim strWhere As String
  3.     Dim lngLen As Long
  4.     Dim varItem As Variant
  5.  
  6.     strWhere = "" ' Main filter
  7.  
  8.  
  9.     'Gender Search
  10.     If Not IsNull(Me.cboGenderSearch) Then
  11.        strWhere = strWhere & " ([tblCandidatesDetails].[Gender] = '" & Me.cboGenderSearch & "') AND "
  12.     End If
  13.  
  14.      'Nationality Search
  15.     If Not IsNull(Me.cboNationalitySearch) Then
  16.        strWhere = strWhere & " ([tblCandidatesDetails].[Nationality] = '" & Me.cboNationalitySearch & "') AND "
  17.     End If
  18.  
  19.       'Academic Level Search
  20.     If Not IsNull(Me.cboAcademicLevelSearch) Then
  21.        strWhere = strWhere & " ([tblCandidatesDetails].[AcademicLevel] = '" & Me.cboAcademicLevelSearch & "') AND "
  22.     End If
  23.  
  24.      'Mother Tongue Search
  25.     If Not IsNull(Me.cboMotherTongue) Then
  26.        strWhere = strWhere & " ([tblCandidatesDetails].[MotherTongue] = '" & Me.cboMotherTongue & "') AND "
  27.     End If
  28.  
  29.      'Military Area Search
  30.     If Not IsNull(Me.cboMilitaryAreaInvolved) Then
  31.        strWhere = strWhere & " ([tblCandidatesDetails].[WhatMilitaryareaInvolvedin] = '" & Me.cboMilitaryAreaInvolved & "') AND "
  32.     End If
  33.  
  34.      'Police Rank Search
  35.     If Not IsNull(Me.cboPoliceRank) Then
  36.        strWhere = strWhere & " ([tblCandidatesDetails].[PoliceRank] = '" & Me.cboPoliceRank & "') AND "
  37.     End If
  38.  
  39.      'Do they need military exp Check box Search
  40.     If Me.chkDotheyhaveaMilitaryBackground = -1 Then
  41.       strWhere = strWhere & "  [tblCandidatesDetails!DotheyhaveaMilitaryBackground] = " & Me.chkDotheyhaveaMilitaryBackground
  42.     End If
  43.  
  44.  
  45.         '''''''''''''''Below is where the problems are'''''''''''''''''''''''''
  46.  
  47.  
  48.         ' Check for SpokenLanguages in multiselect list
  49.  
  50.     If Not IsNull(Me.lstSpokenLang.Column(0)) Then
  51.     For Each varItem In Me.lstSpokenLang.ItemsSelected
  52.         strWhere = strWhere & " ([tblCandidatesDetails!SpokenLanguages] = """ & Me.lstSpokenLang.ItemData(varItem) & """) And "
  53.         Next
  54.     End If
  55.  
  56.           ' Check for Written Languages in multiselect list
  57.  
  58.     If Not IsNull(Me.lstWrittenlang.Column(0)) Then
  59.     For Each varItem In Me.lstWrittenlang.ItemsSelected
  60.         strWhere = strWhere & " ([tblCandidatesDetails!WrittenLanguages] = """ & Me.lstWrittenlang.ItemData(varItem) & """) And "
  61.  
  62.     Next
  63.     End If
  64.  
  65.            ' Check for Professional Experience in multiselect list
  66.  
  67.     If Not IsNull(Me.lstProfessionalExpSearch.Column(0)) Then
  68.     For Each varItem In Me.lstProfessionalExpSearch.ItemsSelected
  69.         strWhere = strWhere & " ([tblCandidatesDetails!ProfessionalExperienceBackground] = """ & Me.lstProfessionalExpSearch.ItemData(varItem) & """) And "
  70.         MsgBox Me.lstSpokenLang.ItemData(varItem)
  71.     Next
  72.     End If                
  73.  '***********************************************************************
  74.     'Chop off the trailing " AND ", and use the string as the form's Filter.
  75.     '***********************************************************************
  76.     'See if the string has more than 5 characters (a trailng " AND ") to remove.
  77.     lngLen = Len(strWhere) - 5
  78.         If lngLen <= 0 Then     'Nah: there was nothing in the string.
  79.             MsgBox "There has been No Crtieria selected", vbOKOnly, "Search Error"
  80.         Else                    'Yep: there is something there, so remove the " AND " at the end.
  81.             strWhere = Left$(strWhere, lngLen)
  82.  
  83.         'Finally, apply the string as the form's Filter.
  84.         DoCmd.OpenForm "frmCriteriaSearchResults", acNormal, , WhereCondition:=strWhere
  85.  
  86.     End If
  87.  End Sub
Sep 29 '09 #1
2 3003
ChipR
1,287 Expert 1GB
The problem is the .ItemData(varItem). varItem is not a valid index into the collection. You would just need to access the string value of varItem. If you want a quick fix, this works, but it goes through each element of the list.
Expand|Select|Wrap|Line Numbers
  1. i = 0
  2. While i < myList.ListCount
  3.   If myList.selected(i) Then
  4.     value = myList.ItemData(i)
  5.     ...
  6.   End If
  7.   i = i + 1
  8. End While
Sep 29 '09 #2
NeoPa
32,556 Expert Mod 16PB
As this thread seems to be a reposting of an earlier thread (Query by form using list boxes) that is still active and members are still spending time trying to help you on I will lock this now. This is very much against the rules and not appreciated in the least.
Sep 29 '09 #3

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

Similar topics

3
by: james.dixon | last post by:
Hi I was wondering if anyone else had had this problem before (can't find anything on the web about it). I have three select elements (list boxes - from here on I'll refer to them as 'the...
1
by: jeffgeorge | last post by:
Trying to create multiple acct reports based on the selection in a list box. I've set the list box for multiple selections, and in the report data source, I have a SQL statement which is reading...
7
by: Siv | last post by:
Hi, I have an MDI application that uses a generic "ShowPage" routine in a module that is called when I want to display a child form. The basic idea is that in the module I have declared each form...
1
by: Rkwarner2 | last post by:
Hello everyone. This is my very first post in this forum. I'm taking my first Visual Basic.Net Class and am wanting to try some new things for one of my homework assignments. The assignment is to...
4
neo008
by: neo008 | last post by:
Hi all, Finally gave up and putting it here. I am new to visual basic stucked up with an error- Run time errors.'-2147217887 (8004021)': Multiple-step operation generated errors. check each...
6
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...
12
by: micarl | last post by:
How would i print a report based on criteria selected from several Combo Boxes as well as multiple Multi Select List Boxes, that are located on the same form? I can get one Multi List Box, just...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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,...

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.