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

Query with an option

I have a query that searches for classes held between a date range:

SELECT EMP_NAMES.LNAME, EMP_NAMES.FNAME, TRAINING.CLASS_ATTD, TRAINING.DATE_ATTD
FROM EMP_NAMES INNER JOIN TRAINING ON EMP_NAMES.UID = TRAINING.UID
WHERE (((TRAINING.CLASS_ATTD) Like ([Enter it the name of the class])) AND ((TRAINING.DATE_ATTD) Between DateValue([Enter the beginning date]) And DateValue([Enter the cutoff date])));

Currently the user MUST enter a date in the date range boxes. What I would like to happen is: If the user hits the enter key (puts nothing in the date boxes) the query continues and reports information containing class information for ALL dates. I'm sure this is a relatively simple IFF statement but, I'm kinda new at this stuff and don't quite know how to state it.

Thanks for your help in advance.

*****************************************
* This message was posted via http://www.accessmonster.com
*
* Report spam or abuse by clicking the following URL:
* http://www.accessmonster.com/Uwe/Abu...9255f3976e2fa7
*****************************************
Nov 13 '05 #1
10 1423
Gary Toth via AccessMonster.com wrote:
I have a query that searches for classes held between a date range:

SELECT EMP_NAMES.LNAME, EMP_NAMES.FNAME, TRAINING.CLASS_ATTD, TRAINING.DATE_ATTD
FROM EMP_NAMES INNER JOIN TRAINING ON EMP_NAMES.UID = TRAINING.UID
WHERE (((TRAINING.CLASS_ATTD) Like ([Enter it the name of the class])) AND ((TRAINING.DATE_ATTD) Between DateValue([Enter the beginning date]) And DateValue([Enter the cutoff date])));

Currently the user MUST enter a date in the date range boxes. What I would like to happen is: If the user hits the enter key (puts nothing in the date boxes) the query continues and reports information containing class information for ALL dates. I'm sure this is a relatively simple IFF statement but, I'm kinda new at this stuff and don't quite know how to state it.

Thanks for your help in advance.

*****************************************
* This message was posted via http://www.accessmonster.com
*
* Report spam or abuse by clicking the following URL:
* http://www.accessmonster.com/Uwe/Abu...9255f3976e2fa7
*****************************************


Here is an example. In the where, I test for start and end. If start
and end are not null, the range is selected. Otherwise it checks for
the status of start and end to see if it is null. Thus there are 4
criteria; Start/End filled in, Start filled in only, End filled in only,
or both weren't filled in.

SELECT Table1.DateField
FROM Table1
WHERE (Table1.DateField) Between [Enter Start] And [Enter End]) OR _
(Table1.DateField>=[Enter Start] And [Enter End] Is Null) OR _
([Enter Start] Is Null And Table1.DateField<=[Enter End]) OR _
([Enter Start] Is Null And [Enter End] Is Null);
Nov 13 '05 #2
"Gary Toth via AccessMonster.com" <fo***@AccessMonster.com> wrote in message
news:34******************************@AccessMonste r.com...
I have a query that searches for classes held between a date range:

SELECT EMP_NAMES.LNAME, EMP_NAMES.FNAME, TRAINING.CLASS_ATTD,
TRAINING.DATE_ATTD
FROM EMP_NAMES INNER JOIN TRAINING ON EMP_NAMES.UID = TRAINING.UID
WHERE (((TRAINING.CLASS_ATTD) Like ([Enter it the name of the class])) AND
((TRAINING.DATE_ATTD) Between DateValue([Enter the beginning date]) And
DateValue([Enter the cutoff date])));

Currently the user MUST enter a date in the date range boxes. What I
would like to happen is: If the user hits the enter key (puts nothing in
the date boxes) the query continues and reports information containing
class information for ALL dates. I'm sure this is a relatively simple IFF
statement but, I'm kinda new at this stuff and don't quite know how to
state it.

Thanks for your help in advance.

*****************************************
* This message was posted via http://www.accessmonster.com
*
* Report spam or abuse by clicking the following URL:
*
http://www.accessmonster.com/Uwe/Abu...9255f3976e2fa7
*****************************************


select EMP_NAMES.LNAME, EMP_NAMES.FNAME, TRAINING.CLASS_ATTD,
TRAINING.DATE_ATTD
from EMP_NAMES INNER JOIN TRAINING ON EMP_NAMES.UID = TRAINING.UID
where
(
TRAINING.CLASS_ATTD Like [Enter it the name of the class]
)
and
(
(
TRAINING.DATE_ATTD >= [Enter the beginning date] or [Enter the
beginning date] Is Null
)
and
(
TRAINING.DATE_ATTD <= [Enter the cutoff date] or [Enter the
cutoff date] Is Null
)
)
--
Your eyes will probably thank you if you stop using all caps for your table
and column names :)




Nov 13 '05 #3
B I N G O!

Thanks a LOT!!

*****************************************
* A copy of the whole thread can be found at:
* http://www.accessmonster.com/uwe/For...s-access/17425
*
* Report spam or abuse by clicking the following URL:
* http://www.accessmonster.com/Uwe/Abu...7d0cb11a882f92
*****************************************
Nov 13 '05 #4
This works well. However, I'm getting extra date range prompts. The one sent by Salad only works if I DON'T put a date range in.

*****************************************
* A copy of the whole thread can be found at:
* http://www.accessmonster.com/uwe/For...s-access/17425
*
* Report spam or abuse by clicking the following URL:
* http://www.accessmonster.com/Uwe/Abu...bc9b19f3e358c5
*****************************************
Nov 13 '05 #5
Gary Toth via AccessMonster.com wrote:
This works well. However, I'm getting extra date range prompts. The one sent by Salad only works if I DON'T put a date range in.

*****************************************
* A copy of the whole thread can be found at:
* http://www.accessmonster.com/uwe/For...s-access/17425
*
* Report spam or abuse by clicking the following URL:
* http://www.accessmonster.com/Uwe/Abu...bc9b19f3e358c5
*****************************************


If mine is failing...make sure the _ are removed. I have OR _ in my
code. In a query builder you don't want them.

Create a table called Table1. It should have 1 field; DateField, type
Date. Enter 5 records; 1/1/2004 to 1/5/2004. Now create a new query.
Go to ViewSQL from the menu and drop this in

SELECT Table1.DateField
FROM Table1
WHERE (Table1.DateField) Between [Enter Start] And [Enter End]) OR
(Table1.DateField>=[Enter Start] And [Enter End] Is Null) OR
([Enter Start] Is Null And Table1.DateField<=[Enter End]) OR
([Enter Start] Is Null And [Enter End] Is Null);

It works for me. You'll notice there are no underbars
Nov 13 '05 #6
"Gary Toth via AccessMonster.com" <fo***@AccessMonster.com> wrote in message
news:c0******************************@AccessMonste r.com...
This works well. However, I'm getting extra date range prompts. The one
sent by Salad only works if I DON'T put a date range in.


Make sure the startt and end date range parameters are all equivalent -
probably a typo somewhere
Nov 13 '05 #7
Checked it over and can't find anything.

FWIW, the prompt in the second box is cut of so it says "Enter the"

If I just hit enter through the second set of prompts, it works fine.

*****************************************
* A copy of the whole thread can be found at:
* http://www.accessmonster.com/uwe/For...s-access/17425
*
* Report spam or abuse by clicking the following URL:
* http://www.accessmonster.com/Uwe/Abu...5fbb5801033904
*****************************************
Nov 13 '05 #8
This is how I got it working...

SELECT EMP_NAMES.LNAME, EMP_NAMES.FNAME, TRAINING.CLASS_ATTD, TRAINING.DATE_ATTD
FROM EMP_NAMES INNER JOIN TRAINING ON EMP_NAMES.UID = TRAINING.UID
WHERE (
TRAINING.DATE_ATTD >= [Enter the beginning date] or [Enter the beginning date] Is Null

)
and
(
(
TRAINING.DATE_ATTD <= [Enter the cutoff date] or [Enter the cutoff date] Is Null
)
and
(
TRAINING.CLASS_ATTD Like [Enter the name of the class]
)
);
Thanks tons!!

*****************************************
* A copy of the whole thread can be found at:
* http://www.accessmonster.com/uwe/For...s-access/17425
*
* Report spam or abuse by clicking the following URL:
* http://www.accessmonster.com/Uwe/Abu...b353e810e6b26e
*****************************************
Nov 13 '05 #9
"Gary Toth via AccessMonster.com" <fo***@AccessMonster.com> wrote in message
news:dc******************************@AccessMonste r.com...
Checked it over and can't find anything.

FWIW, the prompt in the second box is cut of so it says "Enter the"


Line-wrap is the problem
Nov 13 '05 #10
Gary Toth via AccessMonster.com wrote:
This is how I got it working...

SELECT EMP_NAMES.LNAME, EMP_NAMES.FNAME, TRAINING.CLASS_ATTD, TRAINING.DATE_ATTD
FROM EMP_NAMES INNER JOIN TRAINING ON EMP_NAMES.UID = TRAINING.UID
WHERE (
TRAINING.DATE_ATTD >= [Enter the beginning date] or [Enter the beginning date] Is Null

)
and
(
(
TRAINING.DATE_ATTD <= [Enter the cutoff date] or [Enter the cutoff date] Is Null
)
and
(
TRAINING.CLASS_ATTD Like [Enter the name of the class]
)
);
Thanks tons!!


Good you got it to work. Frankly, if it were me, I'd build a form. I'd
have a dropdown to display the classes. I'd then have 2 date fields;
from and to. I'd have a dbl-click to present a calendar. I'd have 2
buttons; OK or Cancel.

If OK is pressed, I'd then build the Where clause...the run the select
or build the recordsource or whatever you are doing.

If I were a user, I'd tire of popups constantly harrassing me for
classnames or dates.

But that's my preference.
Nov 13 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: joemyre | last post by:
Hi everyone, What I'm trying to do is take php variables i got from user input, and pass them as the MySQL query terms. $query = "select * from ident where ".$searchtype1."=".$searchterm1."";...
2
by: JDJones | last post by:
Using PHP and MySQL. Trying to put a list of categories into a drop down select option of a form like: <form name="form" action="<? print $_SERVER?>" method="get"> <select name="subject">...
4
by: Joe | last post by:
I have wrote a script to query my mysql database based up a name that is selected from an HTML list menu, the form action calls to my php script from my html doc, I have tested connectivity to the...
13
by: dogu | last post by:
Noob alert. Code is below. File is saved as a .php. What I'm trying to do: User uses 'select' box drop down list to pick a value. Value ($site) is derived from a db query. This works fine....
7
by: stig | last post by:
hi. coming from postgresql, i am used to textual references to most of the things i do with the database. i feel a little lost with all the graphical. i have few questions regarding MS SQL 2000...
3
by: mkjets | last post by:
I have worked for hours on trying to find a solution and have not figured it out. I am working in Access 2003. I need to create a query that takes values from 1 table and displays them in...
0
by: phlype.johnson | last post by:
I'm struggling to find the best query from performance point of view and readability for a normalized DB design. To illustrate better my question on whether normalized designs lead to more complex...
4
by: TechnoAtif | last post by:
Hi ALL I have entered some array values using checkboxes into mysql database through a form. Next iam creating a searchpage where all those cateogories inserted through checkboxes has to be...
4
by: Joe | last post by:
This is my HTML form: <form method=get action="home.php"> <INPUT TYPE = "Text" VALUE = "" NAME = "title"><br> <select name="searchby"> <option value="Title">Title</option> <option...
11
beacon
by: beacon | last post by:
Hi everybody, I created a database that links one table from an ODBC data source. I saved my password and UID to the data source so neither myself nor anyone else would have to login each time...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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
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
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...

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.