Newbee said:
If cmdView.Caption = "Form View" Then
subFrmView.SourceObject = Form_frmContactCopyof
cmdView.Caption = "Table View"
You are actually replacing the object by making reference to another
object.You do NOT want to use the form_YourFromName reference here.
(the above will cause all kind of problems). In fact, when you ref
form_YourFormName, the form actually loads..and all the events etc fire.
This "copy" that loads will not even been set into the sub form).
Remember, a sub-form on a form is NOT really a sub-form, but simply a
control. You can have a text box control on a form called
zoo
You can then set the data source of that control to any field on the forms
underlying record set.
The same concept applies to a sub-form control....you only have to change
the form NAME of the form that control is supposed to show.
To make a long story short..the SouceObject prootery of a sub-form contorl
is a text (string) seeting. So, you only need to stuff in a string value.
So, to change what form a sub-form contorl uses, you should use:
me.subFrmView.SouceObject = "frmContactCopyof"
Do NOT use the base object of the forms like form_YourFormName
(In fact, if you have this format for "Form_YourFormName" used anywhere in
code...you should remove it)