Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create A report between two dates

Status
Not open for further replies.

Loopyl00

Technical User
Jan 11, 2011
18
0
0
GB
I have managed to create a Report from a form that displays data per date

In the query criteria for the date it references the form

[Forms]![equipe_form]![Date de Vente]

The report is based on the results of the query as per the information entered in the form

so far so good

However, I want the user to be able to select a date range in the form - what do i enter in the query and how do i reference these to fields in the form
 
I rarely us references to controls on forms in queries that are record sources. Consider using code like:
Code:
Dim strWhere As String
Dim strReport as String
strWhere = "1=1 "
strReport = "rptYourReportNameHere"
If not IsNull(Me.txtStartDate) Then
    strWhere = strWhere & " AND [DateField]>=#" & _
        Me.txtStartDate & "# "
End If
If not IsNull(Me.txtEndDate) Then
    strWhere = strWhere & " AND [DateField]<=#" & _
        Me.txtEndDate & "# "
End If
DoCmd.OpenReport strReport, acPrintPreview, , strWhere



Duane
Hook'D on Access
MS Access MVP
 
Thanks for such a quick reply

Does this enable me to enter the date range in the form? the code seems to reference a report

I wanted to have a form where the user selects a date range from a query
 
I was hoping to add two boxes to the form StartDate EndDate and then have criteria in the query Date field

I don't know what this criteria should be
 
I provided sample code that might be behind a command button that will use the values of two text boxes to limit a date range in a report. I assumed that was what you expected.

Duane
Hook'D on Access
MS Access MVP
 
Thanks - I actually managed to create an unbound text box for StartDate and EndDate on the Form then in the Criteria for the query I put

Between [Forms]![Sommaire_Vendeur_Date]![Startdate] And [Forms]![Sommaire_Vendeur_Date]![enddate]

This now runs the query from a form when two dates are entered
 
How are ya Loopyl00 . . .

With a slight modification of the code provided by [blue]dhookom[/blue] the report can show:
[ol][li]Dates [blue]>=[/blue] txtStartDate (Input StartDate Only).[/li]
[li]Dates [blue]<=[/blue] txtEndDate (Input EndDate Only).[/li]
[li]Dates within the input start/end range.[/li]
[li]All dates (no date inputs).[/li][/ol]
Code:
[blue]   Dim Cri As String, rptName As String
   
   rptName = "rptYourReportNameHere"
   
   If Not IsNull(Me.txtStartDate) Then
      Cri = "[DateField]>= #" & Me.txtStartDate & "#"
   End If
   
   If Not IsNull(Me.txtEndDate) Then
      If Cri <> "" Then
         Cri = Cri & " AND [DateField]<= #" & Me.txtEndDate & "#"
      Else
         Cri = "[DateField]<= #" & Me.txtEndDate & "#"
      End If
   End If
   
   DoCmd.OpenReport rptName, acPrintPreview, , Cri[/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Howdy dhookom . . .

Didn't notice until after submission [surprise]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top