How to change a reports RecordSource

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • syedshaffee
    New Member
    • Jan 2012
    • 91

    How to change a reports RecordSource

    Hey people,


    Need Help i want to change the record source of a report template dynamically as per the user selection

    I known the code to do these in form
    Code:
    Forms!Formname.RecordSource = "Query"
    How to do these in report without creating a new Template
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    Syed,
    Your question is a little unclear...

    I am guessing that you have several queries that you want to use with a single report, is that correct?

    If so then you can either pass the query to the report via the docmd.openrepor t "report", option, "qryname" ... http://msdn.microsoft.com/en-us/libr...ffice.12).aspx

    Or, you could do like I do for a different reporting situation where I have the same fields but radically different query conditions and have the report refer to the one query name at design. Then in VBA, delete the old query from the collection, build the new query and save it to the qrydef collection, and open the report.

    Many ways to solve the question.

    -z

    Comment

    • syedshaffee
      New Member
      • Jan 2012
      • 91

      #3
      zmbd Thanx i will try this and get back to you again thanx for your reply

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        If you set the Me.RecordSource value in the Form_Open() event procedure of your report then it only runs it once, as this executes before the data is processed.

        Comment

        • zmbd
          Recognized Expert Moderator Expert
          • Mar 2012
          • 5501

          #5
          Neopa,
          I didn't think about that; however, you're certainly correct... from the OP, I had the impression that Syed was calling the report from an open form - poor assumption on my part.
          -z

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #6
            Originally posted by zmbd
            zmbd:
            I had the impression that Syed was calling the report from an open form
            That can be handled too Z, but which way to handle it would depend on the details of the question. I prefer not to answer each of the possible questions, simply because the OP can't ask their own one properly. It may well be that the OpenArgs parameter might be utilised for this though.

            Comment

            • zmbd
              Recognized Expert Moderator Expert
              • Mar 2012
              • 5501

              #7
              yes
              I'm still learning
              :)
              -z

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32633

                #8
                Sometimes that shows Z, but only very rarely, and even then I suspect only to experienced eyes.

                Of course, we're all in that same position. Even those of us that have been doing it for a number of years. It's a healthy status to see yourself in. I absolutely know it's true for me because I keep finding things I was previously unaware of.

                Comment

                Working...