• Making a label visible when printing (Access 2002)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Making a label visible when printing (Access 2002)

    Author
    Topic
    #363295

    I have a report setup to be printed as the result of an on click event, using VBA. That works as I want. Next step is to have a label that is normally invisible to be visible when this button is clicked. You need to know that the label to become visible is on a subform.

    Thank you. Fay

    Viewing 0 reply threads
    Author
    Replies
    • #554031

      You address any object on a subform via the subform control name (which may or may not be the same as the actual name of the form in the subform). So, in your button’s click event, you can include this to make that label visible:
      Me.subformControlName.Form!LabelName.Visible=True

      • #554036

        This is the line I used and it isn’t working.
        Me.subrptHUDYearlyTotals.Form.lblEndReport.Visible = True
        subrptHUDYearlyTotals is the subreport name
        lblEndReport is the label that I need to be visible.

        I don’t think I am sure what you meant by subformControlName. Also why is the word Form used when calling for a control on a report?

        Thanks for your help.

        • #554055

          Fay,

          It wasn’t clear to me whether the label in question was on your report on or a subform somewhere. It looks like Mark was equally uncertain. In Access 2000/2002, you don’t actually need to use either Form or Report in the syntax (you did in earlier versions), but you will need to use a bang (!) instead of a dot between the name of the subreport control (in this case “subrptHUDYearlyTotals”) and the name of the control on the subreport (“lblEndReport”). So a valid syntax would be:

          Me.subrptHUDYearlyTotals!lblEndReport.Visible = True

          However, I think you may have problems making this work. What are you using to determine whether this label is visible and why? If you’re printing this report as the result of a buttonclick on a form, what purpose is served by having the label hidden in the first place? If it is necessary, why not just use the open event of the report to see if the form is open and if it is, make the label visible?

          • #554068

            The label in question is on the subreport. Thank you for the form info.

            You were correct the code Me.subrptHUDYearlyTotals!lblEndReport.Visible = True did not work.

            Normally this report is printed from a reports switchboard page. But at the end of the grant year I want to be able to mark the report as the year end report, hence the need to make a label visible only once. The button that is clicked is on the main form and only appears in April.

            What I wanted to happen is for the label to become visible prior to printing. How would I use the open event of the report to see if the form is open and make the label visible only when the April button is pressed on the main form? Thanks Fay

            • #554082

              Are you getting the message that says you can’t do this at run-time? Where are you trying to set the label to visible? You’ll need to use the OnOpen event of the subreport to do this. If the button is only visible in April, then the simplest way would be to use the button’s visible property to return the value for the report label’s visible property. Something like this:

              Me.lblEndReport.Visible = Forms!MainForm!cmdApril.Visible

              This code would go in the OnOpen event of the subreport, and I’ve used MainForm for the form name and cmdApril for the name of the button.

            • #554099

              I did what you said in the last post and it worked well until I tried to print the report via the “normal” way. I only want the label visible if I go throught the cmdApril button off the frmClient form. The button is only visible in April. I altered the code to the following

              Private Sub Report_Open(Cancel As Integer)
              ‘Makes the label “End of Year Report” visible _
              during the month of April for this report
              If Month(Date) = 4 Then
              Me.lblEndReport.Visible = True
              Else
              Me.lblEndReport.Visible = False
              End If
              End Sub

              This works. But, isn’t there always a but. Can I alter the “If Month(Date) = 4 Then” line to instead be based on the fact that the cmdApril button was clicked?

              Thanks! Fay

            • #554230

              Not from the report, no. That’s why I suggested referencing the month itself.

        • #554077

          >>Me.subrptHUDYearlyTotals.Form.lblEndReport.Visible = True<<

          Oops! I'm so used to writing this for addressing subforms, that I used .Form instead of .Report! As Charlotte pointed out, you no longer need the .Form or .Report; however, I like to use them as it makes the code easier to read and understand later.

          You have to look at the name of the subreport control on the main report. What is its name. This may or may not be the same as the reportname of the report contained in the control. That's why I used "subformControlName".

    Viewing 0 reply threads
    Reply To: Making a label visible when printing (Access 2002)

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

    Your information: