Report from Query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jas2803
    New Member
    • Oct 2007
    • 30

    Report from Query

    I am not seeing how to accomplish this:
    I created a from that uses a subform, the main form has two fields, category and date.
    After I select a category and date, the appropriate records show in the sub form
    I would like to know how I can send this data to a report that I created using the subform data.
    Right now when I produce the report it displays all the records, I would like to filter the report using the my form/subform data.
    Thanks
    JAS
  • DonRayner
    Recognized Expert Contributor
    • Sep 2008
    • 489

    #2
    In the record source for your report, Add criteria for your for your catagory and date. Base the criteria on your form. The code for the criteria would be something like below or you could just use the expression builder.

    Code:
    [forms]![YourFormName]![YourFieldName]
    Replace YourFormName with the name of your form. Replace YourFieldName with the name of the field that you are basing the criteria on.

    Comment

    • jas2803
      New Member
      • Oct 2007
      • 30

      #3
      I do not understand

      I tried this but I keep getting [forms]![ScheduleLookup]![date] does not exist
      (where Schedulelookup is my form and date is the field on the form

      Is there maybe just a way to filter? where I can filter the report based on the two fields on my main form to return the data in the subform?

      Thanks

      Comment

      • jas2803
        New Member
        • Oct 2007
        • 30

        #4
        still nothing

        I even tried this
        strFilter = "[date]=" & Me![date] & " and [category] ='" & Me![category] & "'"
        stDocName = "Schedule"
        DoCmd.OpenRepor t stDocName, acPreview, , strFilter

        But when I run the report I still get every record.
        The immediate's window show the correct date and category

        Comment

        • DonRayner
          Recognized Expert Contributor
          • Sep 2008
          • 489

          #5
          Is your form open?

          Using "Date" as a field name is probally what's causing the problem. Date is a reserved word in access that represents the current date. You should change the field name on your form to something else like ScheduleLookupD ate or whatever.

          Comment

          • jas2803
            New Member
            • Oct 2007
            • 30

            #6
            this seems to work

            strFilter = "[date]=#" & Me![date] & "# and [category] ='" & Me![category] & "'"

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32633

              #7
              The format for the OpenReport method is :
              Code:
              DoCmd.OpenReport(ReportName, _
                               View, _
                               FilterName, _
                               WhereCondition, _
                               WindowMode, _
                               OpenArgs)
              Naturally you would expect the FilterName parameter to be what you need. It isn't!!

              Set up a WhereCondition string which is like a SQL WHERE clause but without the "WHERE" keyword.

              PS. It's not a good idea to get into the habit of updating the design of an object (report) simply to apply filtering.

              Comment

              Working...