472,347 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,347 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 5622
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....
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...
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...
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...
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....
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...
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...
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...
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...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

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.