conditional opening of subform

  • Thread starter Thread starter DawnTreader
  • Start date Start date
D

DawnTreader

hello

i have a mainform that has a subform on it that loads very slowly. i know
there are probably things i can do to make the subform load quicker, but at
the moment i have a different solution that i would like to see if i can make
work.

i have figured out a way to cause the subform to not load depending on a
check box, but i need to be able to open it after someone checks the box. i
have tried a few different things but i dont think i know how to do this.

can someone pass me some code to load the subform on a on command?
 
Hi Dawn,
something like this
Private Sub Me.chkAName_Click
Dim strSQL as string

strSQL = "q"
'q is the name of a table, a saved query or a sql string
'chkAName is the name of the checkbox
'chkAName is on the main form

me.subform.form.recordsource = strSQL

End Sub

Jeanette Cunningham
 
Hello

ok. to clairify, i dont want to hide a column, i am already not opening the
subform.

the subform resides inside the mainform, they are linked and i have added
code to cause the subform to cancel opening if the checkbox on the mainform
is not checked.

this has the side effect of an error message when i try to "repaint" the
form of "the object doesnt exist".

is there a better way to do what i am attempting? basically if i dont load
this subform the mainform becomes 100 times faster due to the smaller amount
of data to load.

any and all help appreciated. :)
 
Dawn, yes there is a better way.
Make the subform open and visible, but with no records when the main form
loads.
Here are some ideas for you to try.
1.
Initially you can force the form to load with no record, by saving the
RecordSource as:
SELECT * FROM MyTable WHERE (False);


2. define the Record Source as:

"SELECT Fld1, Fld2, Fld3 FROM MyTable WHERE False"

That should return no rows, and avoid the #Name problem.


Jeanette Cunningham
 
DawnTreader said:
hello

i have a mainform that has a subform on it that loads very slowly. i know
there are probably things i can do to make the subform load quicker, but at
the moment i have a different solution that i would like to see if i can make
work.

i have figured out a way to cause the subform to not load depending on a
check box, but i need to be able to open it after someone checks the box. i
have tried a few different things but i dont think i know how to do this.

can someone pass me some code to load the subform on a on command?


You could set or clear the subform control's SourceObject
property.
 
In the Afterupdate event of MyCheckbox
(where ctlSubForm is the name of the subform control (the subform container,
not the subform itself)

If MyCheckbox Then
Me.ctlSubForm.SourceObject = "SubFormName"
Else
Me.ctlSubForm.SourceObject = ""
End If
 
WOO HOO!

thanks George, that was easier than anything i could have hoped for. this
mainform rocks now.

one thing to note, changing the visibility with the source object helped
make it clean looking.

thanks to all for the help!
 
Back
Top