473,396 Members | 1,877 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.

Query criteria question?

I have a query in access 2003 that currently has the following criteria in the "DateAdded" field (which is a date and time stamp):
Expand|Select|Wrap|Line Numbers
  1. Between Now() And Now()-3
  2.  
This obviously brings back only data from the last 3 days.

I would like to keep this the default, but I am trying to add textboxes that the user will be able to look at a certain period of data based on what they enter into boxes "Start Date" and "End Date" that are on the table.

The query is displayed on the same form as the new textboxes that I have created.

When the user enters the form, I have it automatically displaying the query with the default being what I listed above. The "Start Date" and "End Date" boxes will be empty until the user enters dates that they want to see. Then the command button will requery with the following criteria in the "DataAdded" field:

Expand|Select|Wrap|Line Numbers
  1. Between [Forms!]![frmChad]![Start Date] And [Forms!]![frmChad]![End Date] Or Is Null
  2.  
I have this code and the default code working independantly, I just need to know how to have the first be the default and the second work only when dates are entered into the search boxes.

Thanks
Feb 10 '10 #1
5 1552
beacon
579 512MB
I could be completely wrong on this, so if you take my advice please have a backup copy of your DB handy in case my suggestion destroys your work.

I think you can leave the initial criteria in the query, but you need to remove the second criteria (the one for Start/End Date) because the query will expect to receive parameter if the criteria isn't blank.

You should be able to leave the initial criteria, write code to see if the Start/End Date boxes are null or not, then, if they aren't null, execute a query def. Actually, it might be easier to do the query def for the whole thing instead of trying to split up the criteria, but that's up to you.
Feb 12 '10 #2
nico5038
3,080 Expert 2GB
You could use the NZ() function like:
Expand|Select|Wrap|Line Numbers
  1. Between NZ([Forms!]![frmChad]![Start Date],Now()) And NZ([Forms!]![frmChad]![End Date],Now()-3)
  2.  
But I would set the dates on the form to Now() and Now()-3 by default and require both fields to be filled before activating the query.

Nic;o)
Feb 13 '10 #3
Thanks Beacon and Nico! I appreciate your help!
I will check these methods out......
Feb 17 '10 #4
topher23
234 Expert 100+
I second Nico. I've done something similar to several reports to allow users to shortcut commonly used options. Although setting the default in the form is useful, if you call that report from several different forms, keeping them all up-to-date can be a headache.
Feb 18 '10 #5
NeoPa
32,556 Expert Mod 16PB
Unless you want your criteria to start and end in the middle of a day I would stop using Now() for this right away. Date() is more likely what you want and is not likely to throw up any complicated "Why is it selecting those records?" type questions.
Feb 19 '10 #6

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

Similar topics

1
by: Daniel Chartier | last post by:
Hello. I have a question concerning variable criteria for queries and reading forms. Let's say that I have a table with 2 fields and 10 records. One of the fields can have two different...
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...
3
by: thomas goodwin | last post by:
I have a query which asks for a parameter value to execute it. To see the results I have to: a) click on the query -- the "Enter Parameter Value" window pops up. b) enter the parameter value c)...
3
by: Pea | last post by:
Is it possible to get the average in a query where I have multiple criteria? Here's an abbreviated example of the query in design view: Fields: USERID DATE TIME ID_TYPE...
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...
4
by: meganrobertson22 | last post by:
Hi Everyone- I have a question about how to add and then use the "All" selection in a combo box. I am trying to figure out how to: (1) add "All" as a selection to a combo box and then (2)...
7
by: keliie | last post by:
Hello Just a quick question that I've spent a few hours trying to solve with no luck (although one would think this should be fairly easy). I have a form with a subform. The subform is based...
4
by: Stan | last post by:
I am using MS Office Access 2003 (11.5614). My basic question is can I run a query of a query datasheet. I want to use more that one criteria and can not get that query to work. I thought I...
6
by: jmarcrum | last post by:
Hi! I have created a Union Query in ACCESS 2003, that combines 130 records from one query (Extra Foreman Radios) and 250 records from another query (Forman Main Radios). I have created a...
17
by: sharsy | last post by:
Hello guys, I would like some help in generating query criteria that will identify credit cards that have expired on an access database. The specific Field is formatted with a Data Type of...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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
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,...

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.