Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    dmon2010 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Sep 2013
    Posts
    39

    1 Form with 3 print (report) buttons... Please help.

    Hi,

    I'm still pretty new to Access. Using 2007. I need to print 3 different reports. My form has 3 print report buttons. When I click each button, it allows me to print all records in the table. I only want to print the current record. I was able to find the following code that allows me to print the first report properly (only the current record).

    Private Sub Command101_Click()
    On Error GoTo ErrHandler
    DoCmd.OpenReport ReportName:="BoL", View:=acViewPreview, _
    WhereCondition:="ID=" & Me.ID
    Exit Sub


    ErrHandler:
    ' Don't show error message if report was canceled
    If Err <> 2501 Then
    MsgBox Err.Description, vbCritical
    End If


    End Sub

    Where "BoL" is the name of the 1st report I need printed.




    However when I tried using the same code on the other 2 buttons, it doesn't work and prompts me to enter the parameter value (ID). I guess I can only use the code once?

    Also thought about using a single button for all 3 reports, but not all records need all 3 reports. Some need 1 or 2. So a button for each is ideal.

    Any help would be REALLY appreciated here... thanks in advance...

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You're not limited that way. Is ID a field in the other reports? The parameter prompt is Access telling you it can't find something.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    dmon2010 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Sep 2013
    Posts
    39
    ID is a field in the table, but it's not actually on any of the reports. It's just the autonumber primary key field. I found the code itself after searching online. Here's what I found:

    Let's say the record source of your form and of the report(s) has a numeric primary key field ID (for example an AutoNumber field).
    Open the form in design view.
    Select a command button.
    Activate the Event tab of the Property Sheet.
    Click in the On Click event.
    Select [Event Procedure] from the dropdown menu.
    Click the builder dots ... to the right of the dropdown arrow.
    Make the code look like this, substituting the actual names:
    PrivateSub cmdOpenReport1_Click()
    OnErrorGoTo ErrHandler
    DoCmd
    .OpenReport ReportName:="rptMyReport1", View:=acViewPreview, _
    WhereCondition
    :="ID="&Me.ID
    ExitSub

    ErrHandler
    :
    ' Don't show error message if report was canceled
    If Err <>2501Then
    MsgBox Err
    .Description, vbCritical
    EndIf
    EndSubwhere:
    cmdOpenReport1 is the name of the command button.
    rptMyReport1 is the name of the report to be opened.
    ID is the name of the field that uniquely identifies the record.
    If this field is a text field instead of a number field, use
    ...
    WhereCondition
    :="ID="& Chr(34)&Me.ID & Chr(34)
    ...

    Regards, Hans Vogelaar

    I don't really know if that's the code I should be using, but it seems to work. Problem is that it just won't work for the other 2 reports. All 3 reports are based on the same table.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    But is that field included in the record source of the other 2 reports? Can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    dmon2010 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Sep 2013
    Posts
    39
    Sure... But I don't know how... Can you tell me how to post my DB here? It'd be great if you could take a look at it for me.

  6. #6
    dmon2010 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Sep 2013
    Posts
    39
    I think I found it but it says my file's too large. 3.37MB

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Usually if you do a compact/repair then zip it will be small enough.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    dmon2010 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Sep 2013
    Posts
    39
    Database2_Backup.zip Maybe this works...

  9. #9
    dmon2010 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Sep 2013
    Posts
    39
    I'm on the east coast and have to split for lunch but will be back in about an hour. I really really appreciate your time and your help... see you soon.

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The first report is based directly on the table, so it obviously includes the ID field. The other two reports on both based on SQL statements, neither of which includes the ID field. Just add it to both and you should be good to go.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    If you put the ID on the two non functioning reports (set the visible property to FALSE) you'll be fine, just like pbaldy said.

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by rpeare View Post
    If you put the ID on the two non functioning reports (set the visible property to FALSE) you'll be fine, just like pbaldy said.
    Did I not say it well enough? It doesn't need to be on the report at all, just in the record source.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I posted that before your follow up pbaldy, and I was strictly going by going to the design view> field list, ID shows up there so I added it and got the expected result. Two ways to accomplish the same thing.

  14. #14
    dmon2010 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Sep 2013
    Posts
    39
    That worked perfectly!!! Thank you so much for your help!!! I seriously can't thank you enough...

  15. #15
    dmon2010 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Sep 2013
    Posts
    39
    How can I mark this as solved?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Hiding buttons on Print of Report
    By CS_10 in forum Reports
    Replies: 3
    Last Post: 04-08-2014, 07:52 AM
  2. Replies: 6
    Last Post: 03-01-2014, 07:07 AM
  3. Replies: 3
    Last Post: 03-11-2013, 05:11 PM
  4. Replies: 0
    Last Post: 02-22-2011, 05:04 AM
  5. Print Report from Form ID
    By Brian62 in forum Forms
    Replies: 1
    Last Post: 09-18-2009, 01:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums