• use ecordset from form to report (2007)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » use ecordset from form to report (2007)

    Author
    Topic
    #453787

    IS there a way I can use the existing recordset of a form to open a report on that exact recordset?
    The code would be something like this, but this does not work. This would be a command button on a form

    dim rcd as recordset
    set rcd= me.recordsetclone
    docmd.openreport “report”,acdesignview
    report.recordset= rcd

    Thanks

    Viewing 0 reply threads
    Author
    Replies
    • #1124904

      I don’t think you can do that but you can:

      • Set the Recordsource of the report to be the same as the form’s
      • Set the filter of the Report to be the same as the form’s

        [/list]in the On Open event of the form (assuming you did not close the form).

        Me.RecordSource = Forms(“frmListReferrals”).RecordSource
        Me.Filter = Forms(“frmListReferrals”).Filter
        Me.FilterOn = True

      • #1124905

        Thanks. I know I can use that, but it is a form that is data entry and then I want to print a report of just the records entered at that session. So it is not a matter of filtering, but choosing somehow those records that were now entered. I could keep a list of the recordID as they are entered and then filter the report on those ID #’s but that seems a bit of a kludge unless there is no other way.
        If you have any other ideas, I would be grateful (and not dead )

        • #1125351

          You’ll have to use the unique ID of the records, or a timestamp field, for Access itself doesn’t keep track of which records have been entered during a particular session.

          • #1125453

            If the form is still open, is there a way to save the recordset of that moment into a variable that could serve as the recordset of a report that I would open in design view from a command button on the form, before I close the form?

            • #1125455

              You could use the Recordset or RecordsetClone property of the form.

            • #1125467

              I had tried that and it would not work. I get an error 2448 “you cannot assign a value to this object”. The error is on “rpt.Recordset = rst”

              What am I missing?

              This is the code I wrote:

              Private Sub Command35_Click()
              Dim rst As Recordset
              Dim rpt As Report
              Set rst = Me.RecordsetClone
              DoCmd.OpenReport “report1”, acViewDesign
              Set rpt = Screen.ActiveReport
              rpt.Recordset = rst
              DoCmd.OpenReport “report1”, acViewPreview
              End Sub

            • #1125472

              You can’t do it this way, Recordset is not available as a property of reports in a .mdb. And setting it in design view won’t work (you forgot the word Set, by the way)

              You could try this, but I don’t think it’ll do what you want:

              Private Sub Command35_Click()
              DoCmd.OpenReport “report1”, acViewPreview
              End Sub

              and in the code module of the report:

              Private Sub Report_Open(Cancel As Integer)
              Me.RecordSource = Forms!frmTask.Recordset.Name
              End Sub

    Viewing 0 reply threads
    Reply To: Reply #1125467 in use ecordset from form to report (2007)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel