Results 1 to 5 of 5
  1. #1
    Join Date
    May 2010
    Location
    Prison Town, USA
    Posts
    22

    Unanswered: Code to open a report to a filtered record works great in two forms but not in others

    I have two forms on which I have a button that will open a report to the record that is currently being viewed in the form. The forms are identical in every way except for the labels, which are in English on one of the forms and in Spanish on the other one. In both of these forms, the button works great, opening the form to the single record that I am viewing on the form, and not showing any other records on the report, ending at the end of the report for the single record when I scroll down.

    Now I have made two more forms. They are very similar to the first two with a few minor changes in formatting, with the only difference between the two being the language of the labels. I put the exact same code in the button to open the report on these forms, and it opens the report up to the correct record as it should, but upon scrolling down, I see that the report continues on for all records.

    The button is named exactly the same thing on all of the form for consistency sake "Command194). The report is called "rpt_packet"

    This is the code:

    Private Sub Command194_Click()
    If Me.Dirty Then Me.Dirty = False
    DoCmd.OpenReport "rpt_packet", acViewReport, , Me.Filter
    End Sub

    What would be the reason that it works so well on the first two forms but doesn't work the same way and the two new forms? Am I missing something?

    Thanks for you help.

  2. #2
    Join Date
    May 2010
    Posts
    601
    Quote Originally Posted by Glühbirne View Post
    I have two forms on which I have a button that will open a report to the record that is currently being viewed in the form. The forms are identical in every way except for the labels, which are in English on one of the forms and in Spanish on the other one. In both of these forms, the button works great, opening the form to the single record that I am viewing on the form, and not showing any other records on the report, ending at the end of the report for the single record when I scroll down.

    Now I have made two more forms. They are very similar to the first two with a few minor changes in formatting, with the only difference between the two being the language of the labels. I put the exact same code in the button to open the report on these forms, and it opens the report up to the correct record as it should, but upon scrolling down, I see that the report continues on for all records.

    The button is named exactly the same thing on all of the form for consistency sake "Command194). The report is called "rpt_packet"

    This is the code:

    Private Sub Command194_Click()
    If Me.Dirty Then Me.Dirty = False
    DoCmd.OpenReport "rpt_packet", acViewReport, , Me.Filter
    End Sub

    What would be the reason that it works so well on the first two forms but doesn't work the same way and the two new forms? Am I missing something?

    Thanks for you help.
    Your code is designed to print the current set of filtered records. If your filter (Me.Filter) is selecting multiple records, then it should print multiple records. Sounds like it is working correctly.

    You code is NOT really design to actually print the current record, but the current filtered record(s).

    Since your code is assuming the that form is filter to a single record before opening the report, you will need to be sure to filter to a single record before printing.

    If that is not what you want now, then you will need to modify your code to not use the form's filter. I would recommend using the pramary key for the current record in for the Where parameter.
    Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
    Microsoft MVP - Access Expert
    BPM/Accounting Systems/Inventory Control/CRM
    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  3. #3
    Join Date
    May 2010
    Posts
    601
    ... for consistency sake "Command194). The report is called "rpt_packet" ...
    For consistency sake I would not use Command194 as the button name. I would urge you to use meaningful a name for the command button. Something like cmdPrintPacketReport

    IMHO, using Command194 does not guarantee or imply any kind of consistency.

    I would never accept the default name for any command button. IO have found that to be very useful in the past working with Access 15+ years and 1000+ databases.
    Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
    Microsoft MVP - Access Expert
    BPM/Accounting Systems/Inventory Control/CRM
    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  4. #4
    Join Date
    May 2010
    Location
    Prison Town, USA
    Posts
    22
    Okay, the problem was that when I created the new forms (which I did by doing a "Save As" of the old ones) I didn't realize that all of the properties wouldn't be carried over. I went and put the filters back into the new forms and now it's working properly. Thanks.

  5. #5
    Join Date
    May 2010
    Posts
    601
    Quote Originally Posted by Glühbirne View Post
    Okay, the problem was that when I created the new forms (which I did by doing a "Save As" of the old ones) I didn't realize that all of the properties wouldn't be carried over. I went and put the filters back into the new forms and now it's working properly. Thanks.
    You're welcome!
    Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
    Microsoft MVP - Access Expert
    BPM/Accounting Systems/Inventory Control/CRM
    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

Posting Permissions

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