473,472 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Use a single control to query more fields or combo boxes

68 New Member
Hi,
I have a database with tables and fields. I have created a form that with three to four combo boxes and inserted a control button.
I would like a write a code to query my data based on the selection(s) made from the combo boxes when I click the command button.

I have this code and it is working perfectly well, only that I have created multiple command button to perform the queries I need.

Here is what I have:
Expand|Select|Wrap|Line Numbers
  1. Dim Filter As String
  2. Dim strProgram As String, strCohort As String, strCounty As String
  3.  
  4.  If Me![cboSProgram] = "Select Program" Then Exit Sub
  5.  If IsNull(Me![cboSProgram]) Then Exit Sub
  6.  If Me![cboSCohort] = "Select Cohort" Then Exit Sub
  7.  If IsNull(Me![cboSCohort]) Then Exit Sub
  8.  If Me![cboSCounty] = "Select County" Then Exit Sub
  9.  If IsNull(Me![cboSCounty]) Then Exit Sub
  10.  
  11.      strProgram = Nz(Me.cboSProgram, "*")
  12.      strCohort = Nz(Me.cboSCohort, "*")
  13.      strCounty = Nz(Me.cboSCounty, "*")
  14.      Filter = "strProgram = """ & cboSProgram & """ And strCohort = """ & cboSCohort & """ And strCounty = """ & cboSCounty & """"
  15.      DoCmd.OpenForm "tblSortSchools", acFormDS, , Filter
  16.  
  17.      cboSProgram = "Select Program"
  18.      cboSCohort = "Select Cohort"
  19.      cboSCounty = "Select County"
  20.      cboSCohort.Requery
  21.      cboSCounty.Requery
  22.  
In my code, I have two combo boxes but before the control works, I must make both selections. What code can I include that if I make only one selection and click the command button, I still get the query of my selection.

Any idea will be useful.
Nov 18 '13 #1
4 1471
zmbd
5,501 Recognized Expert Moderator Expert
Basically, get rid of all but one of your command buttons.
In the remaining button, you will check for either a selection in the dropdown list and include it or ignore it and then build the string.

Have you taken a look thru the following:
These cover the vast majority of filtering and lookup type form concepts.
Nov 18 '13 #2
Stoic
68 New Member
Thanks zmbd,
I don't seem to catch the option. Can you explain further. My mind is, using one control button that functions/queries multiple selections.
Nov 20 '13 #3
zmbd
5,501 Recognized Expert Moderator Expert
Stoic:

You have me somewhat confused here:

You start with:
that with three to four combo boxes and inserted a control button.
(...)
this code and it is working perfectly well
(...)
only that I have created multiple command button to perform the queries I need.
Ok, comnbine the code fromt he multiple command buttons to review the selections within the comboboxes and build the string to filter.

Then you finish with:
(...)
In my code, I have two combo boxes but before the control works, I must make both selections. What code can I include that if I make only one selection and click the command button, I still get the query of my selection.
Now this is either a second question or an attempt at clarifiyng your goal from the first part of the message which is what I intrepeted this to be hence the links I provided.
These links will take you thru most of what you need to set up filters.

Now you have
using one control button that functions/queries multiple selections.
So are you still looking at multiple comboboxes or have you changed your mind and are now looking at a single combobox with mutliple selections within its dropdown?

-z
Nov 20 '13 #4
Stoic
68 New Member
@zmbd
I am sorry if I confused you, my first question stands. I was only trying to clarify what I meant. Yes, I have the combo boxes label as cboCounty,cboProgram, cboProgram ... each of these combo has a dropdown for selection. I have placed a control button to query base on what I select from the combos. that is working perfectly if I make selection from all three combo, but if I make selection from only one combo box, the button does nothing. So I would like even if I make only one or two selections and leave the other combo empty, and run the command, I should still get my query result.
I hope I am clear on this.
Thanks
Nov 21 '13 #5

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

Similar topics

0
by: Jim | last post by:
Hi, there, I am a beginner on Access. I have been taking so long time to try to figure out his, but so far, no clues. I want to select 2 combo boxes and Access will automatically fill in...
1
by: Cillies | last post by:
Hi! I have a form that displays information using DLookUp. Now at present I am going into the query and entering criteria that I want the form to display. i.e. the form is for a sports team and...
0
by: Andrew | last post by:
Hello, I am trying to create a chart whose underlying query is linked to 2 combo boxes on the same form. I want to pass the values from the combo boxes into the chart query to allow the chart...
2
by: jim | last post by:
I have created a Table that has 13 fields and 2 Primary Keys, e.g. 60 1, 60 2, ... 60 28, 61 1, 61 2, ... 61 28, etc... I want to create a Form where I can input the Primary Key values to query...
2
by: visionstate | last post by:
Hi there, I am working on a form that uses 3 text boxes and 3 combo boxes. When any data is entered into any of these, I click a command button and this requeries a sub query in the form and...
2
by: mpmason14 | last post by:
i know there is a way to populate one combobox based on another, but i've never done it myself and am looking for some help. i have a table that has SwitchNo and NumberofPorts as two columns. i...
2
by: MobiusDick | last post by:
Hi All, I'm in the process of creating a database that allows users to enter details into a form which includes a date range as start and end dates. I have used the inbuilt Calendar Control...
2
by: ARC | last post by:
I'm testing a user's db that contains a very large number of records. I have an invoice screen, with an invoice select dropdown box that shows all invoices, and the customer's name, etc. With...
1
by: hawk7890 | last post by:
I created an access database using access 2003 with lookup tables and I am having isues where my combo boxes on the form update the lookup table instead of the master table. I have a query to my...
0
by: Del | last post by:
Hello and thanks for any and all assistance! I have a database that is used by several users on several different machines. The backend database is housed on a file server. Each user has a...
0
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,...
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,...
0
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...
1
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...
0
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...
0
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,...
1
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...
0
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...

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.