Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Nevada, USA
    Posts
    207
    Thanks
    0
    Thanked 0 Times in 0 Posts

    OpenArgs for a Report (Access 2000)

    I know that the openargs parameter is only valid for docmd.openform but I am looking for something similar when opening a report.

    Here is the situation: I have a report that is opened from two different modules. VBA code is currently used to open the report from the two modules. I would like to be able to pass a parameter to the report that can then be used to put different values in a text box on the report depending on which module is opening it. I know that I can use a table value to do this but I am looking for other possible solutions.

    I hope that this is clear. Any help will be appreciated.
    Carol W.

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

    Re: OpenArgs for a Report (Access 2000)

    Unfortunately for you, OpenArgs for reports was only introduced in Access 2002 (XP).

    There are several possible workarounds for earlier versions:
    <UL><LI>Define a global variable in a standard module. Set the value of this variable just before calling DoCmd.OpenReport, and retrieve it in the OnOpen event of the report.
    <LI>If you have a form that will always be open when the report, you can set the value of a (hidden) text box on the form, and retrieve it in the OnOpen event of the report.
    <LI>As you indicate yourself, you can write a value to a field in a table; this could be retrieved in the OnOpen event, or the table could be included in the Record Source of the report.
    <LI>You could set and retrieve a Registry value using SaveSetting and GetSetting.[/list]HTH

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: OpenArgs for a Report (Access 2000)

    There are a couple of ways to do this.

    Probably the easiest is to set up a public variable to hold the data and a public function to get it. Something like this:

    Public ReportStartDate as Date

    Public function getReportStartDate() as date
    getReportStartDate = ReportStartDate
    end function

    Each of the calling forms populates ReportStartDate before doing the OpenReport. You don't have to use the function to get it from code, but it does help if you want to use it in the SQL behind the report.

    I'm not a big proponent of global variables, but this is one situation in which they work quite nicely.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

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

    Re: OpenArgs for a Report (Access 2000)

    I'll give you another method, the one I use. Open the report in design view and go into the module. Add this to the module in the declarations area:

    Public CalledFrom as String

    This gives the report a public property named CalledFrom. Because it's public, it can be populated from outside the report. So in the form that opens the report, you can do something like this

    Reports!MyReport.CalledFrom = Me.Name

    Another option would be to populate it form the open event of the report by checking to see which form is loaded.

    In the Close event of the report, just retrieve the CalledFrom string and use that to go back to the calling form.
    Charlotte

  5. #5
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Nevada, USA
    Posts
    207
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: OpenArgs for a Report (Access 2000)

    Thanks to all for your suggestions. I am in the process of testing the public variable solution. So far, it looks as if it will work nicely.

    Thanks again.
    Carol W.

Posting Permissions

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