Search code examples
ms-accessms-access-2007vba

how to change control height without overflow the other controls


i have an access form with 20 text-box parallel to each other , i add data to them using multi-select listboxs , the problem is that they have a large space on my form and i dont want all of them i just need the fields that is not empty so i wanted to reduce some space by showing only fields that is not null and hide all the other fields by putting them closed to each other and made their height equal to zero

 If Len(Me.Text0.Value & vbNullString) = 0 Then
 Me.Text0.Height = 0
 else
 Me.Text0.Height = 100
 End if

, so when i update any of these fields its height changes from zero to specific height , but in this case if i have more than one field not empty they overflow each other and i cant see the data of each field , any suggestions ??


Solution

  • If this was a report, I'd say use the Report.CanShrink property...

    However, on a form, you will need to loop through your collapsible ListBoxes and collapse them as necessary, and then, within the ListBox-collapsing loop, loop through all subsequent ListBoxes and deduct the Height of the collapsed listbox from the Top, and also deduct the Height of the collapsed listbox from the form section's Height.

    Turning off screen updating (DoCmd.Echo False...Code...DoCmd.Echo True) while doing all this will probably help.