Share via

Conditionally display form control

Anonymous
2010-07-25T23:51:51+00:00

I know that one can use the visible or enabled properties to control whether or not to show/hide or enable/disable a control.

I was hoping there was a way to show/hide a control but in a way that when it would be visible it would "expand" under another control and when it is hidden in would "shrink".

I do not want to have a blank area left where the control is invisble... so would like to shrink/expand the control.  Can this be done?

Thank you,

QuestionBoy

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2010-07-26T23:24:33+00:00

It can be done by adjusting the form's InsideHeight property. (CanGrow/CanShrink only apply when the form is printed).  But before you can do that, you need to adjust the Top property of all the controls below the one you are hiding to move them up in the form.  And then, of course, you would need to be able to reverse that when you want to unhide the text box

Here's some air code (untested) that might give you an idea:

Const StandardCtrlHeight As Long = .1667 * 1440

Dim ctl As Control

For Each ctl In Me.Controls

   If ctl.Top > Me.DetachedGarageCost.Top _

   Then ctl.Top = ctl.Top - StandardCtrlHeight

Next ctl

Me.InsideHeight = Me.InsideHeight - StandardCtrlHeight

Was this answer helpful?

0 comments No comments

Answer accepted by question author

Anonymous
2010-07-26T05:20:22+00:00

Using a standard Access 2007 textbox height of 315 twips, it should take about 2 seconds to reduce the height to zero if we introduce DoEvents.

'Modify the code like so:

Dim i As Integer

For i = Me!txtMyControl.Height To 0 Step -1

Me!txtMyControl.Height = i

DoEvents

Next i

"Marshall Barton [MVP]" wrote in message news:*** Email address is removed for privacy *** .com...

The computer is quicker than the eye.  ;-)


Regards, Graham R Seach Microsoft Access MVP Sydney, Australia

Was this answer helpful?

0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Anonymous
    2010-07-26T14:17:51+00:00

    I've tried implementing your idea.  I set the form properties shrink and grow to True but the form does not shrink/grow based on the change in height of my controls???  ANy ideas???

        StandardCtrlHeight = inches2Twips(0.1667)

        If Me.DetachedGarage = True Then

            Me.DetachedGarageCost.Height = StandardCtrlHeight

            Me.Label1.Height = StandardCtrlHeight

        Else

            Me.DetachedGarageCost.Height = 0

            Me.Label1.Height = 0

        End If

        DoEvents

    The control does shrink/grow, but the form does not ajust accoringly.  So if I put another control below the "shruken" control and it gets activated, it grows and goes behind the other control rather than the form extending.

    Thank you,

    QuestionBoy

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-07-26T03:14:03+00:00

    The computer is quicker than the eye.  ;-)

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-07-26T00:06:06+00:00

    Take a look at the Height property. You can create a loop that incrementally reduces/increases the control's Height.

    Warning: Aircode - untested. It's just to give you the idea. You can also do it using the control's Top property.

    Dim i As Integer

    For i = Me!txtMyControl.Height To 0 Step -1

    Me!txtMyControl.Height = i

    Next i

    "QuestionBoy" wrote in message news:*** Email address is removed for privacy *** .com...

    I know that one can use the visible or enabled properties to control whether or not to show/hide or enable/disable a control.

    I was hoping there was a way to show/hide a control but in a way that when it would be visible it would "expand" under another control and when it is hidden in would "shrink".

    I do not want to have a blank area left where the control is invisble... so would like to shrink/expand the control.  Can this be done?

    Thank you,

    QuestionBoy


    Regards, Graham R Seach Microsoft Access MVP Sydney, Australia

    Was this answer helpful?

    0 comments No comments