dated range in Query

O

organicpatti

How do I get my query from orders table to list orders for a period of time.
Like from 10-23-06 to 10-27-06.
I would like to make a form to ask me to fill in the dates from _____ to_____
of orders to include on my weekly sales report.
I know I would make a query to select order fields that I want in the report;
but how am I going to tell it to print a weeks worth of totals with the date
range I select and not all orders ever?
 
D

Duane Hookom

Create text boxes on your form [txtFrom] and [txtTo] and use code like:

Dim strWhere as String
strWhere = "1=1 "
If Not IsNull(Me.txtFrom) Then
strWhere = strWhere & " AND [OrderDate]>=#" & _
Me.txtFrom & "# "
End If
If Not IsNull(Me.txtTo) Then
strWhere = strWhere & " AND [OrderDate]<=#" & _
Me.txtTo & "# "
End If
DoCmd.OpenReport "rptYourReportName" , acPreview, , strWhere
 
O

organicpatti via AccessMonster.com

Thank you for your help. I have taken a beginners and a second course and
built a database for my chimney sweep svc. but am still Learning so much!
If you don't mind-

So - do you mean make my text boxes like [OrderDateFrom] and [OrderDateTo] on
my form that asks me what dates to create the report from.
Then do you mean I would go into the properties of the text boxes and use the
"If" expression as my default value and would that mean that the (Me.txtFrom)
would actually read (OrderDateFrom). I don't know what Me.txt means. I am
sorry to ask such dumb questions but I can do so much with my reports if I
can just understand what to do.
Thanks again for all your help.
Patti

Duane said:
Create text boxes on your form [txtFrom] and [txtTo] and use code like:

Dim strWhere as String
strWhere = "1=1 "
If Not IsNull(Me.txtFrom) Then
strWhere = strWhere & " AND [OrderDate]>=#" & _
Me.txtFrom & "# "
End If
If Not IsNull(Me.txtTo) Then
strWhere = strWhere & " AND [OrderDate]<=#" & _
Me.txtTo & "# "
End If
DoCmd.OpenReport "rptYourReportName" , acPreview, , strWhere
How do I get my query from orders table to list orders for a period of
time.
[quoted text clipped - 7 lines]
date
range I select and not all orders ever?
 
D

Duane Hookom

You don't have to set any defaults to your text boxes unless you want.
If you want to open a report, use the Command Button wizard to create the
button that opens your report. Then modify the code in the Event Property to
look similar to the code that I provided.

--
Duane Hookom
MS Access MVP

organicpatti via AccessMonster.com said:
Thank you for your help. I have taken a beginners and a second course and
built a database for my chimney sweep svc. but am still Learning so much!
If you don't mind-

So - do you mean make my text boxes like [OrderDateFrom] and [OrderDateTo]
on
my form that asks me what dates to create the report from.
Then do you mean I would go into the properties of the text boxes and use
the
"If" expression as my default value and would that mean that the
(Me.txtFrom)
would actually read (OrderDateFrom). I don't know what Me.txt means. I am
sorry to ask such dumb questions but I can do so much with my reports if I
can just understand what to do.
Thanks again for all your help.
Patti

Duane said:
Create text boxes on your form [txtFrom] and [txtTo] and use code like:

Dim strWhere as String
strWhere = "1=1 "
If Not IsNull(Me.txtFrom) Then
strWhere = strWhere & " AND [OrderDate]>=#" & _
Me.txtFrom & "# "
End If
If Not IsNull(Me.txtTo) Then
strWhere = strWhere & " AND [OrderDate]<=#" & _
Me.txtTo & "# "
End If
DoCmd.OpenReport "rptYourReportName" , acPreview, , strWhere
How do I get my query from orders table to list orders for a period of
time.
[quoted text clipped - 7 lines]
date
range I select and not all orders ever?
 

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