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

Select Query Criteria from user form

I have a form where the users need to view records for various
criteria, one of which is a date field on which they may wish to view
all related data for the selected date, for all dates upto and icluding
the selected date or all records on or after the selected date

The user selects either "=", >=" or "<=" from a combo box and then a
date from another combobox. The combination of thse two choices is
then set in an unbound textbox so for example the result in the unbound
textbox could be =01/01/2006 or >=01/02/2006 or <=01/03/2005.

Upon pressing a Command button the tableview of a form is opened whose
record source is a select query.

If I set the Criteria in the select query to the date in the form's
date combox the results are displayed
e.g. Criteria =[Forms]![StatementGBP]![INST_DATE]

However I'm trying to set the criteria to either the value in the
unbound textbox or the combination of the two combo boxes so that the
results will be for whichever criteria the user specified i.e.
"=01/01/2006" or ">=01/02/2006" or "<=01/03/2005".

The Criteria ought to be " =[Forms]![StatementGBP]![StatusBox]" where
Statusbox is the name of the unbound control

I have also tried "Like (([Forms]![StatementGBP]![ChoiceBox]) &
([Forms]![StatementGBP]![INST_DATE]))" where both of the comboox values
are concatenated.

Whatever I try doesn't seem to work, I have tried various formatting
functions within the select query, all to no avail. Does anyone know
the solution?

Dec 7 '06 #1
2 5712
The value of a text box on a form can be used as a parameter in a query.
However, you cannot use text boxes to supply operators for the query.

There are various workarounds. If you drop the combo, you could do some
stuff such as:
Between Nz([Forms]![StatementGBP]![INST_DATE],
[Forms]![StatementGBP]![End_DATE])
And
Nz([Forms]![StatementGBP]![End_DATE],[Forms]![StatementGBP]![INST_DATE])
The way that works is that if the user supplies both dates, it treats it as
between, but if they supply only one, it treats as just that date.

Another alternative is to get the to enter both dates the same if they just
want one date, and then use:
WHERE (([Forms]![StatementGBP]![INST_DATE] Is Null)
OR ([MyDateField] >= [Forms]![StatementGBP]![INST_DATE]))
AND (([Forms]![StatementGBP]![End_DATE] Is Null)
OR ([MyDateField] <= ([Forms]![StatementGBP]![End_DATE]))
This one works like this:
- start date only: all records from this date onwards;
- end date only: all records up to this date;
- both dates: only records between the 2 dates;
- no dates: all records.
To get one date only, use enters the same start and end date.

HOWEVER, this whole approach gets very tedious, inefficient, and difficult
to maintain when there are lots of filtering options. A better option is to
build a Filter string form only the boxes where the user entered something.
There's an example of how to do that in this article:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mark Roughton" <mr*******@qbe-europe.comwrote in message
news:11**********************@n67g2000cwd.googlegr oups.com...
>I have a form where the users need to view records for various
criteria, one of which is a date field on which they may wish to view
all related data for the selected date, for all dates upto and icluding
the selected date or all records on or after the selected date

The user selects either "=", >=" or "<=" from a combo box and then a
date from another combobox. The combination of thse two choices is
then set in an unbound textbox so for example the result in the unbound
textbox could be =01/01/2006 or >=01/02/2006 or <=01/03/2005.

Upon pressing a Command button the tableview of a form is opened whose
record source is a select query.

If I set the Criteria in the select query to the date in the form's
date combox the results are displayed
e.g. Criteria =[Forms]![StatementGBP]![INST_DATE]

However I'm trying to set the criteria to either the value in the
unbound textbox or the combination of the two combo boxes so that the
results will be for whichever criteria the user specified i.e.
"=01/01/2006" or ">=01/02/2006" or "<=01/03/2005".

The Criteria ought to be " =[Forms]![StatementGBP]![StatusBox]" where
Statusbox is the name of the unbound control

I have also tried "Like (([Forms]![StatementGBP]![ChoiceBox]) &
([Forms]![StatementGBP]![INST_DATE]))" where both of the comboox values
are concatenated.

Whatever I try doesn't seem to work, I have tried various formatting
functions within the select query, all to no avail. Does anyone know
the solution?

Dec 7 '06 #2
Allen,

Many thanks for your suggestion of using two date fields. I had hoped
that there would be a way to incorporate the operators as that would
have been ideal from the end usrs point of view. However your
suggestion will work just fine and has provided a resolution to my
problem.

Thanks for your input, which as ever, is accurate and most helpful.

Allen Browne wrote:
The value of a text box on a form can be used as a parameter in a query.
However, you cannot use text boxes to supply operators for the query.

There are various workarounds. If you drop the combo, you could do some
stuff such as:
Between Nz([Forms]![StatementGBP]![INST_DATE],
[Forms]![StatementGBP]![End_DATE])
And
Nz([Forms]![StatementGBP]![End_DATE],[Forms]![StatementGBP]![INST_DATE])
The way that works is that if the user supplies both dates, it treats it as
between, but if they supply only one, it treats as just that date.

Another alternative is to get the to enter both dates the same if they just
want one date, and then use:
WHERE (([Forms]![StatementGBP]![INST_DATE] Is Null)
OR ([MyDateField] >= [Forms]![StatementGBP]![INST_DATE]))
AND (([Forms]![StatementGBP]![End_DATE] Is Null)
OR ([MyDateField] <= ([Forms]![StatementGBP]![End_DATE]))
This one works like this:
- start date only: all records from this date onwards;
- end date only: all records up to this date;
- both dates: only records between the 2 dates;
- no dates: all records.
To get one date only, use enters the same start and end date.

HOWEVER, this whole approach gets very tedious, inefficient, and difficult
to maintain when there are lots of filtering options. A better option is to
build a Filter string form only the boxes where the user entered something.
There's an example of how to do that in this article:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mark Roughton" <mr*******@qbe-europe.comwrote in message
news:11**********************@n67g2000cwd.googlegr oups.com...
I have a form where the users need to view records for various
criteria, one of which is a date field on which they may wish to view
all related data for the selected date, for all dates upto and icluding
the selected date or all records on or after the selected date

The user selects either "=", >=" or "<=" from a combo box and then a
date from another combobox. The combination of thse two choices is
then set in an unbound textbox so for example the result in the unbound
textbox could be =01/01/2006 or >=01/02/2006 or <=01/03/2005.

Upon pressing a Command button the tableview of a form is opened whose
record source is a select query.

If I set the Criteria in the select query to the date in the form's
date combox the results are displayed
e.g. Criteria =[Forms]![StatementGBP]![INST_DATE]

However I'm trying to set the criteria to either the value in the
unbound textbox or the combination of the two combo boxes so that the
results will be for whichever criteria the user specified i.e.
"=01/01/2006" or ">=01/02/2006" or "<=01/03/2005".

The Criteria ought to be " =[Forms]![StatementGBP]![StatusBox]" where
Statusbox is the name of the unbound control

I have also tried "Like (([Forms]![StatementGBP]![ChoiceBox]) &
([Forms]![StatementGBP]![INST_DATE]))" where both of the comboox values
are concatenated.

Whatever I try doesn't seem to work, I have tried various formatting
functions within the select query, all to no avail. Does anyone know
the solution?
Dec 8 '06 #3

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

Similar topics

18
by: CJM | last post by:
I'm building a search function for one of my applications. The user has the option to enter a number criteria of criteria, but none are compulsary. I need to be able to build up a query string that...
19
by: William Wisnieski | last post by:
Hello Everyone, I have a main form with a datasheet subform that I use to query by form. After the user selects two criteria on the main form and clicks the cmdShowResults button on the main...
6
by: Andy | last post by:
Hello, I am having many problems with setting up a parameter query that searches by the criteria entered or returns all records if nothing is entered. I have designed an unbound form with 3...
3
by: Matthew | last post by:
I am trying to build a form that has certain criteria on it (combo boxes) which a user can pick from a range of values to specify the criteria he wants when he runs a query on the form. I am...
5
by: SuffrinMick | last post by:
Hello - I'm a newbie to coding! I'm working on an access 2000 database which has three tables: tblContacts - A list of customer contacts. tblOrgTypes - A list of organisational types....
5
by: jjyconsulting | last post by:
Newbie needing some help. I have a tblParticipants. The fields include gender, education_level, income, occupation etc., I'm trying to create a form where a user can run a query from the form and...
1
by: The.Daryl.Lu | last post by:
Hi, two parts to my problem if someone can help address either one or both: 1. I want to SELECT everything in the table if it matches the criteria when the query button is pressed (this is just...
11
by: woodey2002 | last post by:
This problem is driving me crazy. Hello there, i am trying to create a search form for records in my access database. The search form will contain text boxes and a multi select list box. The user...
45
by: dizzydangler | last post by:
Hi, I'm new to access (2007, running on XP), but I've gotten some great help from this site on my project so far. However, the more I know, the more complex the problems seem to become.... I'm...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.