How to check if a subform is fully loaded?

S

ScardyBob

Hello all,

I have a form with two subforms (subfrm1 and subfrm2). When a user
makes a selection in a combo box on the main form, it loads the
appropriate forms into subfrm1 and subfrm2. I have set it up to where
the combo box AfterUpdate event sets the SourceObject property of the
subforms and the UnLoad event of the main form clears it. I encounter a
problem when for some reason the main form closes improperly (error,
Access crashing, etc.) and doesn't clear the subform's SourceObject
properties. The next time the main form is opened, I get an
"'Error': 2455 You Entered an expression that has an invalid reference
to the property Form/Report"
Because the OnCurrent event of subfrm1 refers to the form in subfrm2 as
such:
Set subfrm2 = subctrl2.Form
I've tried getting around this by having subfrm1 check the SourceObject
property of subfrm2, but it always has the correct form input. It
appears that the subfrm2 has been initialized enough to have the
correct SourceObject entered, but not enough to have fully loaded the
form.
Is there a way to check to see if the subform has been fully loaded?

Thanks,
Mike
 
S

Steve Schapel

Mike,

I'm not really sure about this. "The UnLoad event of the main form
clears it" doesn't seem likely to me. What are the Source Object
properties of the subforms set to in the design view of the main form?
I presume they are blank? THis is what they should revert to when the
main form is closed, with no specific intervention by you. Whereas if
the subforms do have a Source Object set in design view, and you "clear
it" when the main form is closed, the original setting will still be in
force when next opened. So I can't really understand what is happening
here. I suppose if it is an MDB as against an MDE, and you are closing
the form using the Close method, and you have the 'Save' argument of the
Close method set to Yes, then this could be the result - but this would
be an unusual setup.
 
S

ScardyBob

Steve,

In the Unload event of the form I have the following code:

For Each ctrl In Me.Controls
If ctrl.ControlType = acSubform Then
ctrl.SourceObject = vbNullString
ctrl.Enabled = False
ElseIf ctrl.ControlType = acComboBox Then
ctrl = vbNullString
End If
Next ctrl

Since I programmatically changed/updated the sourceobject of the
subform controls I figured that I needed to clear the sourceobject via
the above code. I commented out the ctrl.SourceObject = vbNullString
and it did revert back to an empty sourceobject when reopened. However,
it sometimes still sets the sourceobject so that it retains its setting
once the form has been reopened. Although I haven't been able to
determine what specifically causes it, it seems to happen right after
an unhandled error and prompts the user to save the form/subforms.
Maybe accepting the save is causing the form to permanently save their
current sourceobjects? If so, is there a way I can disable the message
and automatically say no so that a user doesn't unwittingly modify the
form structure thinking they are saving their data?

Thanks for the help!
Mike
 
S

Steve Schapel

Mike,

Ok, that makes sense. I absolutely always have an MDE in a usage
situation, in which case design changes are not possible anyway, so that
would solve the problem.

I'm not sure, though, about the idea of an unhandled error resulting in
a prompt to save the form. Of course, if this is happening, I guess you
could try and beef up the error handling :). But such a thing is
unusual, I feel. What options do the users have for closing the form?
Is there a command button to close the form? If so, what is the code there?

By the way, I don't think fiddling with the comboboxes' values will
achieve anything either.
 
S

ScardyBob

Steve,

I a command button to close the form with the code:

subform1.SourceObject = vbNullString
subform2.SourceObject = vbNullString

DoCmd.Close acForm, "frmDATA", acSaveYes
DoCmd.OpenForm "MAINMENU", acNormal, "", "", , acNormal

In reality, the user will probably never encounter this problem since
it rarely happens and only when I have the error handling commented
out. I just like to take as much preventative action as I can to stop
such problems before they happen.
By the way, I don't think fiddling with the comboboxes' values will
achieve anything either.

Probably not, but after I started having this problem, I got a little
paranoid about whether my form was really resetting back to their
design view values. It make be excessive but if it will prevent an
unexpected error from happening, I don't see the harm.

Thanks for all the help!!!
Mike
 
S

ScardyBob

I'm not sure, though, about the idea of an unhandled error resulting in
a prompt to save the form.

Opps, I mispoke a bit. The save prompt happens when the form is closed
(via the close button on the form title bar) after exiting out of the
unhandled error with debug or end. The unhandled error itself doesn't
open the prompt.

Thanks!!
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top