MS Access – Repainting (or similar) needed after subform is collapsed/uncollapsed via height property

I am trying to suppress certain subforms based on conditions in the parent.

The design would have any subforms in the sequence which are suppressed to be removed from the sequence altogether.

I have accomplished this in part by putting all relevant subforms into a table layout and setting them to be both hidden and to have a height of 0. This much works.

However the subforms are not rendered properly, neither those that remain nor those which are unsuppressed upon their return.

I have tried many solutions, including repainting, refreshing, requerying specifically the subform (the parent form requery works, however it requires reloading the particular record, and AFAIK there is no way to preserve the scroll position upon returning), DoEvents, etc…

I have no idea what else to try, or if this is even something that might be possible.

Here is the code executed on the button press to toggle the state (along with lots of comments showing most of the history of my attempts to figure this out).

Private Sub Command1593_Click()
    Dim isVisible As Boolean
    isVisible = Not Me!Label1558.Visible

    'DoEvents
    SuppressControl _
        Me!frmQA_NCR_FollowupSent _
        , isVisible _
        , 2.937 _
        , 0.376
    'DoEvents
    SuppressControl _
        Me!Label1558 _
        , isVisible _
        , 0.556 _
        , 0.053
    'DoEvents
    'Me!frmQA_NCR_FollowupSent.Requery

    'DoCmd.Requery "frmQA_NCR_FollowupSent"

    'Forms!frmQA_NCR.Recordset.Requery

    'Me.Repaint
    'DoCmd.RepaintObject acForm, "frmQA_NCR"
    'DoEvents

    'DoEvents
    'DoCmd.RepaintObject acForm, "frmQA_NCR"
    'DoEvents

    'Me.ScrollBars
    'Me.Requery
    'Me.Recalc
    'Me.Refresh
    'Me.Repaint
    'DoEvents
End Sub

Private Sub SuppressControl( _
    oControl _
    , isVisible As Boolean _
    , dHeight As Double _
    , dPadding As Double _
)
    'MsgBox IIf(isVisible, "Visible", "Hidden") + "  (" + oControl.Name + ")"
    oControl.Visible = isVisible
    oControl.Height = IIf(isVisible, dHeight * dTwipsPerCm, 0)
    oControl.BottomPadding = IIf(isVisible, dPadding * dTwipsPerCm, 0)
End Sub

Here are some screenshots depicting the initial state, the collapsed states and the uncollapsed state (it is not possible to return to the initial state without something that effectively requeries the main form).

Initial State:

Collapsed State:

^ clicking the grey box here focuses the visible subform, and seems to be its true location, despite being rendered where it was initially (note the new position of the second label, where it would be expected)

Uncollapsed State:

EDIT

So I noticed something about the third image: that the grey box there corresponds to the first. I guessed correctly that if I suppressed and immediately unsuppressed the subforms not to be suppressed it would get them to re-render in the right position. It’s a dirty solution, but it does work:

    ' subform(s) suppressed
    SuppressControl _
        Me!Label1558 _
        , isVisible _
        , 0.556 _
        , 0.053
    SuppressControl _
        Me!frmQA_NCR_FollowupSent _
        , isVisible _
        , 2.937 _
        , 0.376
    ' subform(s) kept
    SuppressControl _
        Me!Child1559 _
        , False _
        , 2.937 _
        , 0.376
    SuppressControl _
        Me!Child1559 _
        , True _
        , 2.937 _
        , 0.376

I’m editing rather than answering in case anyone knows of a more deliberate and less indirect solution.

Docmd show form layout
Docmd show form normal

New contributor

Daniel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật