Calling a Report from a Form and passing parameters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • salzan
    New Member
    • Feb 2008
    • 38

    Calling a Report from a Form and passing parameters

    I have a form in which I collect info from the user and then process various tables. Now, I need to call a report and pass two parameters to it so it’ll only select the desired records for reporting. I’m familiar with the application of OpenArgs and used it successfully to pass several parameters to other forms (using a delimiter to separate and then parse the OpenArgs to pick them). I’m wondering if I can do the same with a report and then I’m not sure how to use these values to select only the records I want.

    Any help will be greatly appreciated – even if you can just point me to the right direction to experiment.

    Salzan
  • mshmyob
    Recognized Expert Contributor
    • Jan 2008
    • 903

    #2
    Yes you can use the OpenArgs to pass to a report

    For instance:

    Code in Form

    [CODE=vb]
    ' vPassedVariable is the value you want to pass to the report
    DoCmd.OpenRepor t "rptSample" , acViewNormal, , , , vPassedVariable
    [/CODE]

    Code in the Open Event of the Form

    [Code=vb]
    ' vPassedVariable from the form is now in vGotIt
    vGotIt = Me.OpenArgs
    [/Code]

    That is how to pass a variable to a report.

    To select certain records like you want you might just consider Creating a query and pass the variables to the query and then have the report Record Source set to the query.


    Originally posted by salzan
    I have a form in which I collect info from the user and then process various tables. Now, I need to call a report and pass two parameters to it so it’ll only select the desired records for reporting. I’m familiar with the application of OpenArgs and used it successfully to pass several parameters to other forms (using a delimiter to separate and then parse the OpenArgs to pick them). I’m wondering if I can do the same with a report and then I’m not sure how to use these values to select only the records I want.

    Any help will be greatly appreciated – even if you can just point me to the right direction to experiment.

    Salzan

    Comment

    • salzan
      New Member
      • Feb 2008
      • 38

      #3
      Big Thank You. I was thinking the same about passing params to a query. So I have to ask how do I satify the query with the passed argument? I assume that I still call the report and I have to do something when the report opens to satify the query. I don't know what that is. could you help?

      As always greatly appreciate your help.
      Salzan

      Comment

      • mshmyob
        Recognized Expert Contributor
        • Jan 2008
        • 903

        #4
        Ok assuming you have a Form called frmTest2 and a Query called qryByClientID and a Report called rptByClient.

        In the form you have a Text control called txtClientID. Here you will place a Client ID to get a report on.

        In the query you have column called ClientID (from a table) and in the Criteria row you would put [forms]![frmForm2].[txtClientID].

        This will filter the query based on the ClientID you put in your form.

        Set the Report RecordSource property to qryByClientID.

        On the form have a button that calls the form (you do not need to pass a variable to the report because the query is doing all the filtering work and it picked up the variable Client ID from the form).

        Hope this is clear.

        [
        Originally posted by salzan
        Big Thank You. I was thinking the same about passing params to a query. So I have to ask how do I satify the query with the passed argument? I assume that I still call the report and I have to do something when the report opens to satify the query. I don't know what that is. could you help?

        As always greatly appreciate your help.
        Salzan

        Comment

        • salzan
          New Member
          • Feb 2008
          • 38

          #5
          And Thank you again.

          Now I'm trying to put it all together and for some reason I'm getting a strange result when executing:

          DoCmd.OpenRepor t "ReportName "

          it tries to PRINT it!!! I get a printer prompt - my printer points to a file name so it prompts me for the filename.

          I would think this should simply open the report but it doesn't - any ideas?
          Salzan

          Comment

          • mshmyob
            Recognized Expert Contributor
            • Jan 2008
            • 903

            #6
            There are various ways to use the OpenReport method.

            The 3 common uses are

            [CODE=vb]
            'send to printer - opens print window depending on some settings before executing
            DoCmd.OpenRepor t "rptName", acViewNormal
            ' view report in Print Preview mode
            DoCmd.OpenRepor t "rptName", acViewPreview
            ' view report in Report mode.
            DoCmd.OpenRepor t "rptName", acViewReport
            [/CODE]

            You decide how you want to do it. Your method will open the Print Window.


            Originally posted by salzan
            And Thank you again.

            Now I'm trying to put it all together and for some reason I'm getting a strange result when executing:

            DoCmd.OpenRepor t "ReportName "

            it tries to PRINT it!!! I get a printer prompt - my printer points to a file name so it prompts me for the filename.

            I would think this should simply open the report but it doesn't - any ideas?
            Salzan

            Comment

            • salzan
              New Member
              • Feb 2008
              • 38

              #7
              THANK YOU ALL. I got it working with acViewPreview. acViewReport is not supported in 2003 version. I also tried a hardcoded value 5 and it gave me an error. but Preview works for me.

              Comment

              • mshmyob
                Recognized Expert Contributor
                • Jan 2008
                • 903

                #8
                You're welcome....

                Cheers,

                Originally posted by salzan
                THANK YOU ALL. I got it working with acViewPreview. acViewReport is not supported in 2003 version. I also tried a hardcoded value 5 and it gave me an error. but Preview works for me.

                Comment

                Working...