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

Entering criteria into a query using VBA

31
I have a question on passing data to the criteria of a parameter of a parameter query using VBA. I have a query set up that has ten different fields in it. One is field named “status”, this field contains numbers from 0 to 9 depending on the type of defect a particular part was rejected for. I need to filter the data from the query based on a number or numbers in the status field. On the form that calls this query is a series of 7 check boxes that the user can select from to omit particular data from the record set that’s returned. Multiple check boxes can be selected at the same time. How do I enter the numbers into the criteria field of the status parameter based on the check boxes selected? Do I need to run the query several times for each check box selected, or can I run the query once with several different numbers placed in the criteria field of the status parameter?
Jul 20 '10 #1
2 2263
Delerna
1,134 Expert 1GB
My answer here is based on your question and no thought on my part as to whether what you are doing is the best way to do it or not. I will leave that for you to decide as you are in the best position (as the developer of your database) to make that decision.

Assuming the check boxes are named
Check0 for status=0
Check1 for status=1
etc

The following query is one way to do it
Expand|Select|Wrap|Line Numbers
  1. SELECT The,List,Of,Fields,To,Select
  2. FROM YourTableName
  3. WHERE Status=IIf([Forms]![YourFormName]![Check0].[value],0,-1) 
  4.    Or Status=IIf([Forms]![YourFormName]![Check1].[value],1,-1) 
  5.    Or Status=IIf([Forms]![YourFormName]![Check2].[value],2,-1)
  6.    Or Status=IIf([Forms]![YourFormName]![Check3].[value],3,-1)
  7.    Or Status=IIf([Forms]![YourFormName]![Check4].[value],4,-1)
  8. etc etc
  9.  
Presumably there is no status=-1 so in each IIF the -1 is used for the equality comparison if the checkbox is not ticked and the other number is used if it is
Jul 20 '10 #2
tomric
31
Thank you I will give your suggestion a try.
Jul 21 '10 #3

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

Similar topics

1
by: bdt513 | last post by:
I am trying to extract the values from a query using VBA. Specifically, I want to concatenate all the values of the "rosEmail" field from query "qselRosterEmailList" into one string (strEmails). I...
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...
14
by: Darin | last post by:
I have a table that I want to delete specific records from based on data in other tables. I'm more familiar with Access '97, but am now using 2003, but the database is in 2000 format. In '97, I...
13
by: forbes | last post by:
Hi, I have a user that used the Query Wizard to create a query in Access. Now she claims that her master table is missing all the data that was excluded from the query. Can you create anything...
6
markmcgookin
by: markmcgookin | last post by:
Hi Folks, I am running a simple query using VB (This isnt a VB Question, dont worry!) on SQL Server Compact. I have the query below being created, and then added to if a flower location doesn't...
0
by: =?Utf-8?B?VG9ueSBBLg==?= | last post by:
I'm trying to develop a parameter query using Query Builder, the database is Access 2003. I placed a ? in the column to we quered and linked it to a checkbox on the form. When the user selects an...
1
by: EwanD | last post by:
I am trying to read through and process an Access Query using VBA. I have used the OpenRecordset method with parameters as below OpenRecordset(sSourceRecordset, dbOpenDynaset) Where...
6
by: TSIGOS1 | last post by:
Hello, I have created a query in Access and I want to be able to read the sql statement of the query using vba and then run it from excel vba. That is instead of copying and pasting all the query...
1
by: nico3334 | last post by:
I'm having trouble with a query using "MAX". In my query I'm trying to use 2 date columns as my criteria. Here is the format for each column: Date1: 01/01/2007 Date2: 200701 For my...
3
by: bdavid50 | last post by:
I have an ODBC to several tables in an Oracle 10g installation. I created an Access 2003 query using several of the tables from that ODBC. When I created it, it worked as expected and returned the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...
0
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
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,...

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.