S
Snaux
Here's a weird one:
I have a form that contains a dynamic subform - the subform is not
bound to any data, and instead contains a bunch of labels that I'm
creating dynamically using CreateControl.
Based on user interaction, I sometimes completely change this subform.
I set the SourceObject to empty (to unbind the subform from the Main
form), delete the subform, recreate the subform with new controls, and
rebind it to the main form:
formMain.subFormObject.SourceObject = ""
If FormExists("SubForm") Then
DoCmd.DeleteObject acForm, "SubForm"
End If
Set formSub = CreateForm
strSub = formSub.Name
'
' I add my custom controls to the form here
'
' Then I close and rename the subform, and rebind it:
DoCmd.Close acForm, strMultiBar, acSaveYes
DoCmd.Rename "SubForm", acForm, strSub
formMain.subFormObject.SourceObject = "SubForm"
90% of the time, this works just fine, and the subform is replaced with
new data correctly. Every so often, however, a real shocker occurs;
even though the Subform itself is deleted and recreated perfectly (you
can open it in design view to verify), the DISPLAY of the subform, when
it appears in the main form, it will show a previous (and deleted)
version of the subform.
if you open the sub by itself... it's fine!
I know what's going on - the database is looking at its garbage heap
for the form instead of looking at the live version. And indeed, doing
a "Compact And Repair" fixes the problem, but this seems a little
drastic (and it screws up my app in doing so).
Is there anything I can do to prevent and/or repair this odd behaviour
without actually repairing the entire database?
I have a form that contains a dynamic subform - the subform is not
bound to any data, and instead contains a bunch of labels that I'm
creating dynamically using CreateControl.
Based on user interaction, I sometimes completely change this subform.
I set the SourceObject to empty (to unbind the subform from the Main
form), delete the subform, recreate the subform with new controls, and
rebind it to the main form:
formMain.subFormObject.SourceObject = ""
If FormExists("SubForm") Then
DoCmd.DeleteObject acForm, "SubForm"
End If
Set formSub = CreateForm
strSub = formSub.Name
'
' I add my custom controls to the form here
'
' Then I close and rename the subform, and rebind it:
DoCmd.Close acForm, strMultiBar, acSaveYes
DoCmd.Rename "SubForm", acForm, strSub
formMain.subFormObject.SourceObject = "SubForm"
90% of the time, this works just fine, and the subform is replaced with
new data correctly. Every so often, however, a real shocker occurs;
even though the Subform itself is deleted and recreated perfectly (you
can open it in design view to verify), the DISPLAY of the subform, when
it appears in the main form, it will show a previous (and deleted)
version of the subform.
onto the main form, it still displays as its previous incarnation. ButFrom this point on, even if I physically drag a new copy of the subform
if you open the sub by itself... it's fine!
I know what's going on - the database is looking at its garbage heap
for the form instead of looking at the live version. And indeed, doing
a "Compact And Repair" fixes the problem, but this seems a little
drastic (and it screws up my app in doing so).
Is there anything I can do to prevent and/or repair this odd behaviour
without actually repairing the entire database?