I need a form that will ask begining and ending dates for a report

G

Guest

I'm needing to create a form to set the start date and end date for printing
records in a report. I want to print all records between the two dates.

I'm sure this is a very basic operation, but I haven't found any examples of
code anywhere for this.

I would like to create a form with two fields "date1" and "date2" (the field
in my table is "date") to set my query filter, and then a control button that
will create the report. I already have a report written, I just need to
minipulate the filter/query.

Any ideas?
 
T

T Martin

You can do this one of two ways:

1. You can create a Query from the Table or Query that your report is based
on. In the Date field criteria use the following:
=[forms]![frmName]![Date1] and <=[forms]![frmName]![Date2]
Also you would need to change the "Record Source" in your report to the new
query.

2. You can create a Toggle button on your form and in the event code use
the following code:
docmd.openreport "MyReport",,"[date] >= ' " & me.date1 & " ' and <= ' " &
me.date2 & " ' "

Both these methods should accomplish what you are trying to do.
 
D

DebbieG

You probably should rename your Date field (to something like MyDate) because it could cause problems later.


| I'm needing to create a form to set the start date and end date for printing
| records in a report. I want to print all records between the two dates.
|
| I'm sure this is a very basic operation, but I haven't found any examples of
| code anywhere for this.
|
| I would like to create a form with two fields "date1" and "date2" (the field
| in my table is "date") to set my query filter, and then a control button that
| will create the report. I already have a report written, I just need to
| minipulate the filter/query.
|
| Any ideas?
 
F

fredg

I'm needing to create a form to set the start date and end date for printing
records in a report. I want to print all records between the two dates.

I'm sure this is a very basic operation, but I haven't found any examples of
code anywhere for this.

I would like to create a form with two fields "date1" and "date2" (the field
in my table is "date") to set my query filter, and then a control button that
will create the report. I already have a report written, I just need to
minipulate the filter/query.

Any ideas?

Do you really have a field named "Date"?
Date is a reserved Access/VBA/Jet word and should not be used as a
field name.
See the Microsoft KnowledgeBase article for your version of Access:

109312 'Reserved Words in Microsoft Access' for Access 97
209187 'ACC2000: Reserved Words in Microsoft Access'
286335 'ACC2002: Reserved Words in Microsoft Access'
321266 'ACC2002: Microsoft Jet 4.0 Reserved Words'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top