Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Apr 2002
    Location
    Arkansas, USA
    Posts
    163
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Opening Report with new recordsource (Access 2000)

    I have a main form (frmMain) that contains a subform (subformdata) that has a recordsource of nothing when the main form starts. There are four options that the user selects in order to determine the recordsource of the subform. Each selection chooses a different query to populate the recordsource for the subform. The user can then use the shortcut menu to filter the data in the subform. I want the user to have the ability to print the filtered data based on the record source that was selected and the filter being applied. I have created a report that contains the columns I want displayed, but cannot get the code correct to open the report using the current recordsource and the filter being used by the subform. I tried on the onclick event of the cmd button that opens the report and on the on open event of the report, but am apprently missing something as I either get no data or a VBA error.

    Any assistance would be appreciated.

    Thanks in advance.

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Opening Report with new recordsource (Access 2000)

    You can't do this by just opening a report with the form filtered. You will have to pass the report the necessary information for it to filter the values. If the recordsources all have the same shape (the same fields, datatypes, etc.) and the report is generic for the results, you can use code to open the report in design view and change the recordsource. However, If you're allowing the users to filter the form on the fly, that doesn't affect the recordsouce, so you would have to pass a filtercondition to the report as well in the DoCmd.OpenReport statement you use to actually open the report in Print or Preview mode (not design view).
    Charlotte

  3. #3
    2 Star Lounger
    Join Date
    Apr 2002
    Location
    Arkansas, USA
    Posts
    163
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening Report with new recordsource (Access 2000)

    I understand the concept, but am having difficulty in accomplishing the coding for the open event for the report. Is there a way to code the on open event of the report to make the recordsource and filter equal the recordsource and filter of the subform?

    For the on open event of the report i tried to use but received an error

    me.recordsource=[forms]![frmMain]![subformData]!recordsource
    me.filter=[forms]![frmMain]![subformData]!filter

    Am i on the right track?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Opening Report with new recordsource (Access 2000)

    The RecordSource and Filter are properties of the subform as a form, not of the subform as a control on the main form. To specify that you are using properties of the form, use this:

    Me.RecordSource=Forms![frmMain]![subformData].Form.RecordSource
    Me.Filter=Forms![frmMain]![subformData].Form.Filter

  5. #5
    2 Star Lounger
    Join Date
    Apr 2002
    Location
    Arkansas, USA
    Posts
    163
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening Report with new recordsource (Access 2000)

    Thanks Hans, that was the help I needed. It works perfectly now.

Posting Permissions

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