Results 1 to 8 of 8
  1. #1
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    use ecordset from form to report (2007)

    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

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: use Recordset from form to report (2007)

    I don't think you can do that but you can:
    <UL><LI>Set the Recordsource of the report to be the same as the form's
    <LI>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
    Regards
    John



  3. #3
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: use Recordset from form to report (2007)

    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 )

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: use Recordset from form to report (2007)

    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.

  5. #5
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: use Recordset from form to report (2007)

    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?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: use Recordset from form to report (2007)

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

  7. #7
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: use Recordset from form to report (2007)

    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

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: use Recordset from form to report (2007)

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •