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
Daniel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.