Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    May 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Subform criteria (Access 97)

    I have a form that is based on a query that also includes a subform based on a different query. I have set up a date criteria for the main form that is Between [Beginning Date] and [Ending Date]. I would like to set the subform criteria to be a set beginning date and get the ending date from the main form. I tried setting the date criteria on the subform query to read Between #01/01/02# and Form![MainForm].[Ending Date] but this does not work. I am asked for the Beginning Date and then for the Ending Date and then for the Form![MainForm].[Ending Date]. I am asked for this twice. Is there any to have the subform get its ending date from the main form query?

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Subform criteria (Access 97)

    In the on open or on load event of the mainfrom set the following code:

    <pre>Me.SubFormControlName.Form.Filter = "DateFieldOfSubForm Between " & _
    DMin("DateFieldMainform",Me.RecordSource) & " and " & _
    DMax("DateFieldMainForm",Me.RecordSource)
    Me.SubFormControlName.Form.FilterOn = True</pre>


    I can't test it here as I have no such data but maybe you'll have to add the #
    <pre>Me.SubFormControlName.Form.Filter = "DateFieldOfSubForm Between #" & _
    DMin("DateFieldMainform",Me.RecordSource) & "# and #" & _
    DMax("DateFieldMainform",Me.RecordSource) & "#"
    Me.SubFormControlName.Form.FilterOn = True</pre>

    Francois

  3. #3
    New Lounger
    Join Date
    May 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Subform criteria (Access 97)

    Thanks, Francois, for your quick response. My original question should have been about a report and subreport not forms. But I tried your code in my report. I am a real novice when it comes to writing code. I ran the report without changing the criteria in my subreport query and it did not work at all. I then deleted the criteria in the query and tried running the report. I got the main report and the subreport OK but the subreport information was not limited to the dates specified on the main report. It appeared to include all of my records. To explain my report, I have a main report showing my total sales for month by rep and my subreport shows total ytd sales by rep. So I want the main report to be for the dates entered in a dialog box and the subreport to be a fixed beginning date (e.g. 01/01/02) and the ending date to be the same as the main report ending date. Pretty confusing, I know. Is this possible?

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Subform criteria (Access 97)

    I think, without trying it, that it would work if you put the code in the On Format event of the detail section of the report.
    <pre>Me.SubReportControlName.Report.Filter = "DateFieldOfSubForm Between #01/01/02# and #" & _
    DMax("DateFieldReport",Me.RecordSource) & "#"
    Me.SubReportControlName.Report.FilterOn = True</pre>

    Francois

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •