473,837 Members | 1,499 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 3049
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,584 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
2420
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
3092
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. Does anyone have any insight or direction on how I might add?
7
3119
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" which is the name of the form I wish to open), I first check to see if we already have an instance...
1
1880
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: Description, Credit, Debit, Balance, in an effort to emulate the look of a real checkbook ledger. The...
4
4035
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
9435
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:...
12
4052
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
4683
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 problem. I've copied the working code from my working list boxes, however it cant seem to pick up the...
1
6807
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 multiple sources eg ,multi select list boxes , combo boxes. I have a subform showing all the...
0
9682
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
10871
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...
1
10621
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
10268
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7806
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5668
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...
0
5846
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4474
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
2
4039
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.