473,320 Members | 2,193 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,320 software developers and data experts.

Changing criteria of a stored query with code

I've been working on this for a while and I can't get the syntax right. I'm trying to use code to change the criteria of a stored query so I can toggle whether or not Null values are included in the search. If anyone knows a better way, or can just get the me proper coding to do this, it would be extremely helpful. Thanks.
Apr 9 '07 #1
1 1743
ADezii
8,834 Expert 8TB
I've been working on this for a while and I can't get the syntax right. I'm trying to use code to change the criteria of a stored query so I can toggle whether or not Null values are included in the search. If anyone knows a better way, or can just get the me proper coding to do this, it would be extremely helpful. Thanks.
Assumptions:
  1. Table name = Employees
  2. Query Name = qryLastName
  3. OUTPUT: All Records in the Employees Table where [LastName] = King
Expand|Select|Wrap|Line Numbers
  1. Debug.Print CurrentDb.QueryDefs("qryLastName").SQL     'produces
  2.  
  3. SELECT Employees.*
  4. FROM Employees
  5. WHERE (((Employees.LastName)="king"));
Now, modify the SQL Property of the QueryDef Object:
Expand|Select|Wrap|Line Numbers
  1. CurrentDb.QueryDefs("qryLastName").SQL = "SELECT Employees.*, Employees.LastName FROM 
  2. Employees WHERE Employees.LastName='Archibald';"
Expand|Select|Wrap|Line Numbers
  1. Debug.Print CurrentDb.QueryDefs("qryLastName").SQL     'now produces
  2.  
  3. SELECT Employees.*, Employees.LastName
  4. FROM Employees
  5. WHERE Employees.LastName='Archibald';
Apr 10 '07 #2

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

Similar topics

6
by: AAVF | last post by:
Hi We have a problem with a query. An Access database links via ODBC to a UNIX server. To speed things, we use the ODBC to load the relevant tables to the local PC that runs Access so that...
2
by: neptune | last post by:
I have a query where each customer has an or . Sometimes both fields for a customer are populated, but if is null, then will be populated and vice versa. I have a form, , where I select a...
5
by: M Wells | last post by:
Hi All, Is it possible to use form criteria in a query / view in an Access 2003 ADP with SQL Server as the backend? ie something like: select * from mytable where recid = forms!! I'm...
10
by: Marizel | last post by:
I'm not sure there's an easy solution to this, but thought I'd ask. I often find myself with a query which I'd like to reuse, but with a different datasource. These datasources generally have...
3
by: MLH | last post by:
Am repeating question with different subject heading, perhaps stating more clearly my problem... I have an A97 query (qryVehiclesNowners2) that has a table field in it named . Depending on the...
2
by: starke1120 | last post by:
I have a main form with a text box on it "txtSearch" onlost focus it updates another text box "txtSearchString" to include a quote and asterik before and after the value of txtSeach. I then...
11
by: Purdue02 | last post by:
I am trying to pass a global variable to criteria in a query using the below code, but the query is returning no results. I have the function ReturnStrCriteria() included in the query's criteria....
8
by: Dr Al | last post by:
I have a table with four date fields, some of which may not be filled in based on our data entry needs. I have a criteria set as <date()-180 which is supposed to pull dates older than 180 days ago....
3
by: Darkside12 | last post by:
Hi, I'm trying to build a dynamic query by form. The idea is that a user can select a table in the database via a combo box and this will then change all of the text box labels on the form to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.