473,569 Members | 2,836 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple List boxes using QBF

5 New Member
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 3021
ChipR
1,287 Recognized Expert Top Contributor
The problem is the .ItemData(varIt em). 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,564 Recognized Expert Moderator MVP
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
2403
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 list boxes'). Users can add and remove items from the list boxes. When the users are adding and removing items, the list boxes are single
1
3063
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 the list box(when there is a single selection) but no luck with multiple selections. I'm suspecting I need to write a bit of code using an array. ...
7
3093
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 as follows: Friend F0 As frmMain Friend F1 As frmStart Friend F2 As frmSearch Then in my ShowPage routine (which is passed a string "pageToShow"...
1
1857
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 create a windows application that will allow a user to balance a checkbook. Visually speaking, I want to use multiple list boxes, to display the data:...
4
4016
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 status value. Error comes at ADODC.RECORDSET.UPDATE command.
6
9395
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....
12
4022
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 not several, to report using this code i found - Private Sub cmdPreview_Click()
6
4656
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...
1
6784
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...
0
7695
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...
0
7612
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...
0
8119
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...
1
7668
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...
1
5509
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...
0
5218
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...
0
3653
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...
1
2111
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
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.