Using queries to pull up reports...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neosam
    New Member
    • Mar 2008
    • 47

    Using queries to pull up reports...

    Hey,

    Have been working on a project which requires a report to be pulled when a query is run. Pulling the report is something i have done, but if i have to filter the reports to pull up only certain data is something which i havent been able to master. Is that possible. To filter data in a report something like we do in a excel sheet??
  • RuralGuy
    Recognized Expert Contributor
    • Oct 2006
    • 375

    #2
    The WhereCondition argument of the OpenReport command simply applies a filter to the report. That sounds like the answer you were looking for but I'm not sure.

    Comment

    • neosam
      New Member
      • Mar 2008
      • 47

      #3
      Originally posted by RuralGuy
      The WhereCondition argument of the OpenReport command simply applies a filter to the report. That sounds like the answer you were looking for but I'm not sure.
      Hey, could you let me know how do you declare a where condition. is it like a seperate function?

      Comment

      • JKing
        Recognized Expert Top Contributor
        • Jun 2007
        • 1206

        #4
        Originally posted by neosam
        Hey, could you let me know how do you declare a where condition. is it like a seperate function?
        Hey there,

        The OpenReport command like many other commands has several parameters or arguments that you can use to change how the report acts when opened. If you don't specify all the parameters the default settings are used.

        Here is what all the arguments are:

        OpenReport(Repo rtName, View, FilterName, WhereCondition, WindowMode, OpenArgs)

        The only required argument is a report name. You can leave an optional argument blank in the middle of the syntax, but you must include the argument's comma. If you leave one or more trailing arguments blank, don't use a comma following the last argument you specify.

        In your case I think you only want to use the report name and the where condition. This would look something like the following:

        Code:
        DoCmd.OpenReport "myReport", , , "ID = 'ABC1' "
        myReport would be the name of the report you want to open and ID is a field you want to be filtered to show only ABC1.

        If you need help forming your where condition to your specific case feel free to ask and provide some information as to what fields you need filtered and their data type.

        Good luck,
        Jking

        Comment

        • neosam
          New Member
          • Mar 2008
          • 47

          #5
          Originally posted by JKing
          Hey there,

          The OpenReport command like many other commands has several parameters or arguments that you can use to change how the report acts when opened. If you don't specify all the parameters the default settings are used.

          Here is what all the arguments are:

          OpenReport(Repo rtName, View, FilterName, WhereCondition, WindowMode, OpenArgs)

          The only required argument is a report name. You can leave an optional argument blank in the middle of the syntax, but you must include the argument's comma. If you leave one or more trailing arguments blank, don't use a comma following the last argument you specify.

          In your case I think you only want to use the report name and the where condition. This would look something like the following:

          Code:
          DoCmd.OpenReport "myReport", , , "ID = 'ABC1' "
          myReport would be the name of the report you want to open and ID is a field you want to be filtered to show only ABC1.

          If you need help forming your where condition to your specific case feel free to ask and provide some information as to what fields you need filtered and their data type.

          Good luck,
          Jking
          Hi Jking,

          This works but it does not open the report in a .xls format, but in a .mdi format.
          The code i have used is
          Code:
          DoCmd.OpenReport "myReport", , , "Date = TxtBox "
          where TxtBox is a text box where user needs to type a date. When i do this application automatically opens a "Save As" Dialog box, but there is no .xls option.

          Comment

          • JKing
            Recognized Expert Top Contributor
            • Jun 2007
            • 1206

            #6
            Originally posted by neosam
            Hi Jking,

            This works but it does not open the report in a .xls format, but in a .mdi format.
            The code i have used is
            Code:
            DoCmd.OpenReport "myReport", , , "Date = TxtBox "
            where TxtBox is a text box where user needs to type a date. When i do this application automatically opens a "Save As" Dialog box, but there is no .xls option.
            Sorry, I think you also need to add the view argument. You probably want acViewPreview.

            If you want to use a control in the where clause you would need to break it out of the quotes and reference it properly.

            Code:
            DoCmd.OpenReport "myReport, acViewPreview , ,"Date = #" & Me.TxtBox & "#"

            Comment

            • neosam
              New Member
              • Mar 2008
              • 47

              #7
              Originally posted by JKing
              Sorry, I think you also need to add the view argument. You probably want acViewPreview.

              If you want to use a control in the where clause you would need to break it out of the quotes and reference it properly.

              Code:
              DoCmd.OpenReport "myReport, acViewPreview , ,"Date = #" & Me.TxtBox & "#"
              Hi Jking,

              Thanks a lot... it works...

              Comment

              Working...