Access Report: Hiding field and Label when field is null

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dantebothermy
    New Member
    • Nov 2008
    • 47

    Access Report: Hiding field and Label when field is null

    Hi all:

    On Access 2003: I have a tabular form with labels next to the associated fields. I'd like them both to dissappear when the associated field is null. ("Can Shrink" will do this for the field, but the label is still there, so the report does not shrink.)

    Any ideas how I can make the label shrink too?

    Thanks,
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    Simply change the label to a text box with no backcolor, and set conditional formatting so that if the value is null ( or [control] = "" ), the text is the same color as the background. You will want to lock and disable the text box so the text can't be selected when it is not supposed to be visible.

    Comment

    • dantebothermy
      New Member
      • Nov 2008
      • 47

      #3
      I found a different answer

      Thanks.

      Actually, I found a different answer: I changed the label to a text box and set the control source to iif(isnull([related control]),null,"Label Title"). Then I set the Can Shrink properties for the label and the related to control to Yes.

      Comment

      • ChipR
        Recognized Expert Top Contributor
        • Jul 2008
        • 1289

        #4
        Thank you for sharing your solution. That's probably a much better idea, since I've experienced slow updating with conditional formatting.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #5
          Each section in a report has a Format event. You could handle this without any special usages of controls simply by setting the .Visible property of both controls to (Not IsNull(Me.Contr ol)).

          Comment

          • ChipR
            Recognized Expert Top Contributor
            • Jul 2008
            • 1289

            #6
            Ah, I was thinking of continuous forms. Would the Format event work in that case? Forgive my laziness in not trying it myself, but I think it's quicker to ask.

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32633

              #7
              Originally posted by ChipR
              Forgive my laziness in not trying it myself, but I think it's quicker to ask.
              Not at all. Happy to answer.

              I believe the Format event is specific to Report sections and is not available anywhere I can find for forms.

              Comment

              • dantebothermy
                New Member
                • Nov 2008
                • 47

                #8
                NeoPa,

                I admit I'm baffled. (I'm only a programmer by circumstance, not by training.) Note, I'm using Access 2003.

                1: What's the "Format event". Is that the format tab in the properties of the form?
                2: I can't put that code in dialog box for Is Visible -- it limits me to Yes and No

                Can you explain? Thanks.

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32633

                  #9
                  I will be happy to. Unfortunately, I will need to be careful to explain it in terms that make sense to you which will take time I don't have immediately available.

                  If you see nothing by tomorrow bump the thread and I'll post a proper explanation.

                  Comment

                  • dantebothermy
                    New Member
                    • Nov 2008
                    • 47

                    #10
                    NeoPa,

                    Thanks for the offer, but it's not necessary; I have a solution that works. But if you're willing to give me 3 or 4 minutes, (and no more) I'd like to understand where to put the code you suggest -- do I go into code builder and build a sub called control_format( ...); if so, is it attached to the control or to the form definition?


                    Thanks,


                    Dante

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32633

                      #11
                      OK. Here goes. A little intro to programming in VBA and the structures you can work with.

                      Most code in VBA is instigated by events. There are various objects (such as forms; reports; controls on either forms or reports; etc; etc). Typically objects have various events associated with them. An event can be considered as a trigger for starting specific relevant code - generally termed an Event Handler Procedure.

                      I won't go into too much detail of all the possible events for all the possible objects as they are really far too numerous to mention. To put this in context though, a report has various sections, each of which has a Format event associated with them. Forms don't have any objects with a Format event as far as I'm aware, so this should be considered exclusively for reports.

                      When assigning code to an event, what you need to do is the following (to start you off right) :
                      1. Open the containing object in Design Mode (if the object is a form or report then it won't be contained).
                      2. Select the object (control; section; etc).
                      3. Show Properties and select the Event from the list.
                      4. The value will have a drop-down and the value "[Event Procedure]" will be available. Select this and click on the ellipsis button to the right.
                      5. This will switch to the IDE (Integrated Development Environment) and create a procedure shell for you to populate with your code.

                      Comment

                      • dantebothermy
                        New Member
                        • Nov 2008
                        • 47

                        #12
                        Thank you NeoPa. You helped me find the one piece of the puzzle that I was missing. I'd been looking for the events associated with the controls, or at the form level, but not at the detail section level. Now I see the "on Format" event.

                        Thanks again.


                        Dante

                        Comment

                        • NeoPa
                          Recognized Expert Moderator MVP
                          • Oct 2006
                          • 32633

                          #13
                          Pleased to help Dante, though still a little curious that you refer only to Forms when talking about the Format event. You do appreciate that this is fundamentally Report related rather than anything to do with Forms as such?

                          Comment

                          • dantebothermy
                            New Member
                            • Nov 2008
                            • 47

                            #14
                            My mistake; I meant reports.

                            Thanks again

                            Comment

                            Working...