missing subforms in error checking

V

VBAgroupie

Hi. I've tried to think of scenarios that cause fatal errors. How do I
check for a missing subform on a main form? If the subform is missing I
don't want the main form to open. I've tried several things but can't seem
to get it to work when opening the form from the switchboard or the custom
menu. It works when I open the form from design view when I'm testing the
form. Should I even worry about this scenario? Thanks!
 
K

KARL DEWEY

How do I check for a missing subform on a main form?
The main form will have a blank spot where the subform should be.
Just fix what is missing.
 
W

Wolfgang Kais

Hello VBAgroupie.

VBAgroupie said:
Hi. I've tried to think of scenarios that cause fatal errors.
How do I check for a missing subform on a main form?
If the subform is missing I don't want the main form to open.

You could try something like this in the form's open event:

On Error GoTo Err_FormOpen
Dim ctl As Control
Dim sName As String
For Each ctl In Me.Controls
If TypeOf ctl Is SubForm Then sName = ctl.Form.Name
Next
Exit Sub
Err_FormOpen:
Cancel = True
Resume Next
I've tried several things but can't seem to get it to work when
opening the form from the switchboard or the custom menu. It works
when I open the form from design view when I'm testing the form.

You could use a wrapper function that opens the form that uses
inline error handling: On Error Resume Next
Should I even worry about this scenario? Thanks!

Don't. In a well tested application, no subform is missing.
 
Top