• Changing Label Caption on Report

    Author
    Topic
    #487566

    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

    Viewing 5 reply threads
    Author
    Replies
    • #1372230

      Interestingly, the value is actually being changed but not displayed! If you use the immediate window of the VBE and enter the command [noparse]?Reports!rptTest.Label0.Caption[/noparse] 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 :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1372239

      That worked. Thank you very much!

    • #1372325

      You could do this in the OnOpen event of the report.

      • #1372359

        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.

    • #1372434

      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.

      • #1372453

        Thanks Patt but I am not fimiliar with using OpenArgs. What would the code look like?

    • #1372559

      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

    • #1372562

      You can look at this post for an example and make sure you read to the end for an important gotcha! HTH :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    Viewing 5 reply threads
    Reply To: Changing Label Caption on Report

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: