Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Nov 2002
    Location
    Mt. Olive, North Carolina, USA
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Changing Label Caption on Report

    I have been able to change the caption on a label in a report from a command button on a form in the past but I am not able to now. I don't see what I am doing different. Attached is a very simple example. Click on the command button and it should bring up the preview of the rptTest with the label caption changed to invoice. Please take a look at it and see if you have any ideas. Thank you. Access2000
    Attached Files Attached Files
    Last edited by imincorrigible; 2013-01-31 at 09:33.

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Interestingly, the value is actually being changed but not displayed! If you use the immediate window of the VBE and enter the command ?Reports!rptTest.Label0.Caption it will return "invoice" but that's not what shows on the preview of the report.

    Here's a workaround:
    Code:
        stDocName = "rptTest"
        DoCmd.OpenReport stDocName, acViewDesign
        Reports!rptTest.lblinvoice.Caption = "Invoice"
        DoCmd.Save
        DoCmd.Close
        DoCmd.OpenReport stDocName, acViewPreview
    BTW: In the code above I named the label lblInvoice vs Label0 because I thought this might be causing the problem and it's a good idea to name your labels for ease of reading code anyway.
    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. The Following User Says Thank You to RetiredGeek For This Useful Post:

    imincorrigible (2013-01-31)

  4. #3
    2 Star Lounger
    Join Date
    Nov 2002
    Location
    Mt. Olive, North Carolina, USA
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts
    That worked. Thank you very much!

  5. #4
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts
    You could do this in the OnOpen event of the report.

  6. #5
    2 Star Lounger
    Join Date
    Nov 2002
    Location
    Mt. Olive, North Carolina, USA
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts
    My plan is to have a print command on the form that gets filled out. The print command button prints 4 copies of the report. On each copy of the report the label will change. Thank you for replying.

  7. #6
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts
    You could pass that value through to the report as an OpenArgs and then set it up in the OnOpen event of the report.

    Just another way of doing it.

  8. #7
    2 Star Lounger
    Join Date
    Nov 2002
    Location
    Mt. Olive, North Carolina, USA
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Thanks Patt but I am not fimiliar with using OpenArgs. What would the code look like?

  9. #8
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts
    Look at the DoCmd.OpenReport command, there is an argument on that line.

    In the OnOpen event of the report it is just:
    lblinvoice.Caption = Me.OpenArgs
    Last edited by patt; 2013-02-01 at 19:20.

  10. The Following User Says Thank You to patt For This Useful Post:

    imincorrigible (2013-02-01)

  11. #9
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    You can look at this post for an example and make sure you read to the end for an important gotcha! HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  12. The Following User Says Thank You to RetiredGeek For This Useful Post:

    imincorrigible (2013-02-01)

Posting Permissions

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