By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,696 Members | 1,512 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,696 IT Pros & Developers. It's quick & easy.

Query Expression

P: 10
In a query i have a criteria for pulling records entered by current month, but i have to keep constantly changing the dates as we go into another month.
Example: Between #4/1/2008# And #4/30/2008# for April. Then when we enter May I would then go and change the date criteria.

My question is if there is a way to just have the criteria change according to the current month. I tried using "Month(Now())", it works but it gives me
all the orders of the current month but in any given year. Also would there be a way to check previous records entered in previous months by selecting from a combo box which would have the months listed. Like selecting January for example and the query would then set the criteria to Between #1/1/2008# And #1/31/2008#.
Apr 2 '08 #1
Share this Question
Share on Google+
3 Replies


P: 68
you could create a form with a date from and date to field, you could also code buttons for those boxes for current week, month, year, and even today then in your query criteria (assuming the form is form1 and the text boxes for the dates are datefrom and dateto;
Expand|Select|Wrap|Line Numbers
  1. >=[forms]![Form1]![DateFrom] And <=[forms]![Form1]![DateTo]
  2.  
this will allow you to pull dates by a specified date

you will also need to set up your report containing all fields you want in the report, with the same fields in the query, if you have more or less fields you may end up getting an enter peramiter dialogbox
Apr 2 '08 #2

P: 10
you could create a form with a date from and date to field, you could also code buttons for those boxes for current week, month, year, and even today then in your query criteria (assuming the form is form1 and the text boxes for the dates are datefrom and dateto;
Expand|Select|Wrap|Line Numbers
  1. >=[forms]![Form1]![DateFrom] And <=[forms]![Form1]![DateTo]
  2.  
this will allow you to pull dates by a specified date

you will also need to set up your report containing all fields you want in the report, with the same fields in the query, if you have more or less fields you may end up getting an enter peramiter dialogbox
I have already fields that contain the datefrom and dateto. I just don't know how to put it into code so that i don't have to be entering the dates in specific, but rather just being able to select for example "June" then it would have already the dates from and to for the month of June.
Apr 3 '08 #3

NeoPa
Expert Mod 15k+
P: 31,754
If you have a ComboBox with month dates in (must include the year of course - EG. January 2008) then your WHERE clause would look something like this :
Expand|Select|Wrap|Line Numbers
  1. WHERE [DateField] Between CDate(Forms!frmYourForm.cboMonth) And DateAdd('m',1,Forms!frmYourForm.cboMonth) - 1
Apr 6 '08 #4

Post your reply

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