Maurita:
Rather than using a simple parameter, create an unbound dialogue form,
frmDowntimeDlg say, with two text boxes, txtStart and txtEnd. In both the
queries reference the form's controls as the parameters. I'd suggest you use
a different method of defining the data range by looking for dates on or
after the start date and dates before the day after the end date. This
allows for the possibility of dates having a non-zero time of day element,
which unless you have taken specific steps in the table design to prevent
this is a theoretical possibility which would prevent records with dates on
the last day of the range being returned.
Also on you form add a couple of command buttons, one to preview thereport
and one to print it. The button wizard can set these up for you easily or
you can put the code in the buttons' Click event procedures yourself, which
gives you the chance to validate that both dates have been entered:
If Not IsNull(Me.txtStart + Me.txtEnd) Then
DoCmd.OpenReport "YourReportName" ' print thereport
Else
MsgBox "Both dates must be entered.", vbExclamation, "Invalid
Operation"
End If
For the code for the preview button just change the second line to:
DoCmd.OpenReport "YourReportName", View:=acViewPreview ' preview thereport
In the queries its also a good idea with date parameters to declare them as
DateTime as otherwise they might be interpreted by Access as arithmetic
expressions and give thewrongresult. So taking this and the different way
of defining the date range into account each query would be something like
this:
PARAMETERS
Forms!frmDowntimeDlg!txtStart DATETIME,
Forms!frmDowntimeDlg!txtEnd DATETIME;
SELECT [Date], <more fields>
FROM [YourTable]
WHERE [Date] >= Forms!frmDowntimeDlg!txtStart
AND [Date] < Forms!frmDowntimeDlg!txtEnd+1;
Yours may well be more complex of course, but all you really have to do is
open each query in design view, switch to SQL view and add the PARAMETERS
clause, and amend the WHERE clause.
Instead of opening thereport, open the form, enter the dates and click one
of the buttons.
You don't say on what fields, if any, thereportandsubreportare linked.
This might have a bearing on the fact that you are getting only one record in
the subform. Or it could be something in the query itself. Its difficult to
diagnose the cause of this without knowing more of the details.
Finally I'd recommend that you don't use Date as a field name as it's the
name of a built in function and could cause confusion. Wrapping the field
name in square brackets should avoid this, but using a more explicit name
such as InvoiceDate, TransactionDate etc. would be far better.
Ken Sheridan
Stafford, England
Maurita said:
Hi, I hope someone can help me with aSubreportproblem I can't seem
to figure out. I have a "Downtime-Query" and a "Downtime-Subquery".
Within the "Downtime-Query" I have a "Date" field with Criteria of,
Between [EnterReportSTART Date] AND [EnterReportEND Date]. When
the "Downtime-Report" is opened, the query criteria is requested. The
problem I am having is that if the same date range (12-12-06 and
12-12-06) are put in the criteria thereportandsubreportare
correct, BUT, if I use a different date range (1-1-06 and 12-12-06), I
only get a single date on thesubreportand the the correct date range
(1-1-06 thru 12-12-06) in thereport.
How can I tie the query criteria to both the form and subform since I
have the pop up box asking for date criteria.
Maurita Searcy- Hide quoted text -
- Show quoted text -