Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    May 2001
    Location
    Oxfordshire
    Posts
    456
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Open report/form from selected record (2003+)

    Not sure if I'll be able to explain this properly, but here goes;

    I'd like a continuous form, showing the records in the main table, with a button alongside each record. When this button is clicked, I'd like a report to open showing that single record.

    I know this is do-able, but don't have the knowledge.

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

    Re: Open report/form from selected record (2003+)

    Let's say that the records displayed in the form have a field ID that uniquely identifies them (for example an AutoNumber field). I will assume that it is numeric.

    Create a command button cmdReport in the Detail section of the form.
    The On click event procedure will look like this:
    <code>
    Private Sub cmdReport_Click()
    If Not IsNull(Me.ID) Then
    DoCmd.OpenReport ReportName:="rptSomething", View:=acViewPreview, WhereCondition:="ID=" & Me.ID
    End If
    End Sub
    </code>
    where rptSomething is the name of the report.

  3. #3
    4 Star Lounger
    Join Date
    May 2001
    Location
    Oxfordshire
    Posts
    456
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open report/form from selected record (2003+)

    Thank you, I can see the logic there.

    I'm unsure, however, how to tie in the code with the Record source for the report; I'm getting a run time error 3075; Syntax error (missing operator).

    The ID field is named ID, but the field data is alpha-numeric eg 'EA 001'.

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

    Re: Open report/form from selected record (2003+)

    The record source for the report should be the table.

    For a text field, change the line that opens the report to
    <code>
    DoCmd.OpenReport ReportName:="rptSomething", View:=acViewPreview, WhereCondition:="ID=" & Chr(34) & Me.ID & Chr(34)
    </code>
    Chr(34) is the double quote character ".

  5. #5
    4 Star Lounger
    Join Date
    May 2001
    Location
    Oxfordshire
    Posts
    456
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open report/form from selected record (2003+)

    That did it!

    Cheers Hans, have a <img src=/S/trophy.gif border=0 alt=trophy width=15 height=15>

Posting Permissions

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