since you only run the code on the load event - which only runs the once, this is to be expected. So you need to find an event that runs when you want it to run - perhaps the current event, perhaps the afterupdate event, you will need to experiment
Yes I figured that out. But solving this issue was to create a new module with this code, and call It from Form_Load and Combobox_AfterUpdate Event (control on subform). From Current or afterUpdate code doesn't work...
Here's complete code (changed a little bit - see Sub shrink_grow) :
Code:
Private Sub Form_Load()
Call shrink_grow 'You call this from Master form
End Sub
Code:
Private Sub Combo5_AfterUpdate()
'This is afterUpdate event of the subform control
If IsNull(Combo5) Then
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
End If
Call shrink_grow
End Sub
Code:
Sub shrink_grow()
'Code that shrinks/grows subform control according to records in continous form, needs to be inserted in module
Const MaxRecs As Integer = 10
Dim NumRecs As Integer
On Error Resume Next
With Forms![TblName]![TblJoin].Form
.RecordsetClone.MoveLast
NumRecs = .RecordsetClone.RecordCount
If NumRecs > MaxRecs Then NumRecs = MaxRecs
.InsideHeight = NumRecs * .Section(0).Height + 1650
End With
End Sub
I hope this helps someone, I find It very useful for me. Problem is only when you have some other controls under subform and you need to move them when subform resizes. But that is another issue, which I'm facing too and will need to open different thread and discuss about It there
Solution can be seen in attached sample - open TblName, you'll see subform where surnames like "Deere" are displayed. You can delete/add those records and subform will resize automatically.