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

Criteria in Query Problem!

Hi,
I have a query but don't know what criteria to type in. I would like to return all fields with a date during the month and year selected. I have made a 'Date selector' form, with a month and year drop down menu. Then when you clik OK I would like the results of the query (for the chosen month and year) to come up.

I hope you can understand this, if not tell me and I will try to rewrite a bit better!.
Many thanks,
Grant
Oct 11 '06 #1
4 3113
pgirl
13
Here's one way you could do it.

1. Create a query - let's say you call it qryEvents.
Add all the fields you want to display.

Let's say the date for the "event" is stored in event_date field. Add another two fields - Call one
Expr1: Month([event_date])
and the other
Expr2: Year([event_date])

This will extract the month and date for the event.

The criteria for month will be the value in the selected month in the form you've created:
[Forms]![frmEvents]![cboMonth]

The criteria for year will be the value in the selected year
[Forms]![frmEvents]![cboYear]

2. Create a report (rptEvents)
Add all the fields you want to display in your report. (you could also display them in the form if you want - the theory is the same).

Change the control source for the report to the query you created. (qryEvents)

3. Add a button to the form you created. If you use the button wizard you can choose REPORT OPERATIONS and choose rptEvents (or whatever your report is called).

Now when you open the form and choose a month and year you can click the button. This will launch the report and call on the query you created. It will read the month and date from the form and filter the query to display all the events in the report.

If you want to show all the records in the form it is almost identical. Let me know if you want to do this.
Oct 12 '06 #2
Thanks for the help, but when I press run I get an error saying, "Duplicate output alias 'Expr1'".
Any ideas why this could be?
Many thanks
Oct 12 '06 #3
pgirl
13
You may have another Expr1 - it's just a named expression. You can go into design view in the query and call it anything you like. Try renaming it.
Oct 15 '06 #4
jimatqsi
1,271 Expert 1GB
You might find it helpful to use the Format function to return a result to test your criteria against. Add a field to your query something like this:
Expand|Select|Wrap|Line Numbers
  1.  MMMYY: Format([datefieldname],"MMMYY")
This will return a value of "JUN06" for any date during the month of June 2006. So you could actually put "JUN06" for the criteria, but hopefully you will generalize it by putting
Expand|Select|Wrap|Line Numbers
  1. Format([someotherdatefield],"MMMYY")
in the criteria. The "someotherdatefield" can be a parameter from a table or maybe from a text box on a form. If you make a criteria like this:
Expand|Select|Wrap|Line Numbers
  1. Format (date(),"MMMYY")
then you will get only stuff for the current month.

Check out the Format function. Lots of cool stuff you can do with it.

Jim
Oct 15 '06 #5

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

Similar topics

3
by: Laurel | last post by:
this is driving me crazy. i need to use a form control as a criteria in a select query, and the control's value is set depending upon what a user selects in an option group on the form. the query...
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...
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...
0
by: MLH | last post by:
I have an A97 query (qryVehiclesNowners2) that has a table field in it named . Depending on the selections made in a number of criteria choices on a form, a field on the form will have string...
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...
10
by: Daniel | last post by:
In Microsoft Access I can write a query that includes the criteria: Between Date()-7 And Date() to retrieve the records from a table that fall within the last week. I'm trying to write a...
2
by: Mark Roughton | last post by:
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...
49
by: martin DH | last post by:
Hello all, I'm back with another SQL related problem. The details are below, but in short: I am using Access 2003. I have a table whose structure may include four different associate names per...
8
by: limperger | last post by:
Hello everyone! First and foremost, my apologies for the title of the post. It is not very clarifying of what the problem is about, but I didn't know how to put it... My problem is as follows: I...
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: 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
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...
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
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
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.