loading subforms at runtime

K

Kurt

I have a main form (frmMedicalIntake) with a tab control
(TabCtl). TabCtl has five pages which are named:

- pgIntake
- pgPhysical (has subform "frmExamPhysical")
- pgSexual (subform "frmExamSexual")
- pgLabs (subform "frmLabs")
- pgPerps (subform "frmPerps")

The main form takes a while to load due in part to all
the subforms. To improve performance, I'm trying to have
the subforms load at runtime, when the user clicks on the
tab. I tried to follow the methods described in
http://advisor.com/doc/05401 (about 2/3rds down under"
Increasing tabbed-form performance") but when I click on
a tab I get:

"Object doesn't support this property or method."

Debugging highlights the first Case listed under the
Select Case procedure of the tab control's On Change
event (in this case, "pgPhysical").

Here's what I did:

1. I set the visible properties of the subforms to False
and left the SourceObjects blank.

2. I created a class module called Class1. The article
said to assign the constants in the "Declaration section
of the form's class module," but I'm not sure if this
module is connected to the form or not. This may be the
problem.

Const pgIntake = 0
Const pgPhysical = 1
Const pgSexual = 2
Const pgLab = 3
Const pgPerp = 4

3. I added this to the On Change event of the tab control:

Private Sub TabCtl_Change()

Select Case TabCtl
Case pgPhysical
If Len(Me!frmExamPhysical.SourceObject) = 0 Then
Application.Echo True, "Loading Page, Please
wait..."
Me!frmExamPhysical.SourceObject = _
"frmExamPhysical"
Me!frmExamPhysical.Visible = True
Application.Echo True
End If
Case pgSexual
If Len(Me!frmExamSexual.SourceObject) = 0 Then
Application.Echo True, "Loading Page, Please
wait..."
Me!frmExamSexual.SourceObject = _
"frmExamSexual"
Me!frmExamSexual.Visible = True
Application.Echo True
End If
'etc.
End Select

End Sub

###

Any idea what I'm missing?

Thanks. - Kurt
 
A

Albert D. Kallal

1. I set the visible properties of the subforms to False
and left the SourceObjects blank.

You don't really have to set the visible property...but I guess that idea is
ok....

Source Objects blank is good...
2. I created a class module called Class1. The article
said to assign the constants in the "Declaration section
of the form's class module," but I'm not sure if this
module is connected to the form or not. This may be the
problem.

The above simply means that you put the code in the forms module. A forms
module code is often referred to as the forms class module. So, your
"question" as to how, or why the two get connected is a good one (since, the
answer is there is only ONE class module for the form!!). So, you do NOT
have to create another module here..but simply put your constants in the
forms module code (or, now what we know to call the forms class module!).
Any idea what I'm missing?

You almost got it right .

And, the performance increase is great...since all those forms etc. don't
load!...

Good luck...
 
G

Guest

2. I created a class module called Class1. The article
The above simply means that you put the code in the
forms module. A forms module code is often referred
to as the forms class module.

That's what I did the first time, and I've just tried it again. But when the
form loads I get:

"The expression On Load you entered as the event
property setting produced the following error:

Member already exists in an object module from
which this object module derives."

Any ideas?

Kurt
 
G

Guest

I spoke too soon.

I initial put the constants outside of the TabCtl_Change routine. I've since
moved them inside of the routine, as in...

Private Sub TabCtl_Change()

Const pgIntake = 0
Const pgPhysical = 1
' etc.

Select Case TabCtl
Case phPhysical
' etc.

.... and now it works.

Thanks!

Kurt
 

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