Distinguish a From and a subForm

W

Warrio

Hello!

I use a form which is used twice: 1st as a SubForm and 2nd as a mainForm.

If the two forms are opened and I try to refer to the mainForm, it effects
the subForm ?!!?!

I know that if I want to refer to the subForm, I have to use :
MainForm.SubForm.Form.Property, but this time it respons even with
SubForm.Property..

How can I avoid this?

Thanks for any suggestion
 
R

Rick Brandt

Warrio said:
Hello!

I use a form which is used twice: 1st as a SubForm and 2nd as a mainForm.

If the two forms are opened and I try to refer to the mainForm, it effects the
subForm ?!!?!

I know that if I want to refer to the subForm, I have to use :
MainForm.SubForm.Form.Property, but this time it respons even with
SubForm.Property..

How can I avoid this?

Thanks for any suggestion

What exactly is affected? There is still only one form. If you change
something on it you should expect both instances to reflect that (properties,
not data).

It is very unusual to have a form that is simultaneously used as a subform and
as a form. If you really need this I suggest making a copy to use for the
subform.
 
W

Warrio

the property that I'm trying to change is the record source. and I'm using
the form as object especially to create many instances and do not have many
copies to avoid the to make changes many times.

I can't imagine that Microsoft didn't think about that before...
 
D

Douglas J. Steele

What's the code you're using to change the record source, and where does
this code run from?
 
W

Warrio

I'm running the code form an independent form (let's call it Form3) with:
Sub ChangeRs()
Docmd.OpenForm "Form1"
From_From1.Recordsource = "SELECT ..."
End sub

And the Form1 is opened separately and a second time in Form2.
So basically, I have:

Form1

Form2
Form1

And Form3 which is trying to change the recordsource of Form1 (the main one,
not the sub)
 
R

Rick Brandt

Warrio said:
the property that I'm trying to change is the record source. and I'm using the
form as object especially to create many instances and do not have many copies
to avoid the to make changes many times.

I can't imagine that Microsoft didn't think about that before...

I just tested this in Access 97 and the change to the RecordSource property in
the form opened outright had no effect on the same form contained within a
subform. I doubt that this would have changed in newer versions, buy I suppose
it's possible.
 
W

Warrio

I still need to check when exactly this change happens on the subform.
maybe because the main form that contains the subform was the last loaded or
the last that had the focus..
 
R

Rick Brandt

Warrio said:
I still need to check when exactly this change happens on the subform.
maybe because the main form that contains the subform was the last loaded or
the last that had the focus..

I even tried open Form1, changing RecordSource to "", then opening Form2 which
has Form1 as a subform. The subform still showed data and was editable.
 
D

Dirk Goldgar

Warrio said:
Hello!

I use a form which is used twice: 1st as a SubForm and 2nd as a
mainForm.

If the two forms are opened and I try to refer to the mainForm, it
effects the subForm ?!!?!

I know that if I want to refer to the subForm, I have to use :
MainForm.SubForm.Form.Property, but this time it respons even with
SubForm.Property..

How can I avoid this?

Warrio -

Reading through your other messages in this thread, I see that you are
using the class object syntax to refer to the form; e.g.,

Form_Form1.RecordSource = ...

This is a *bad* idea, specifically because of the sort of problem you're
experiencing here. If Form1 is open both as a main form and as a
subform, there are two distinct instances of the form open at the same
time. Using the syntax above, you have no idea which of those instances
is going to be affected. Your code might change the recordsource of
either one. Furthermore, if there happens to be *no* instance of Form1
loaded at the moment, referring to it as Form_Form1 will cause it to be
loaded, rather than raising an error, which is usually what you would
want.

Instead, use Forms!Form1 or Forms("Form1") to refer to the default
instance of Form1 that is currently open as a main form, and
Forms!FormOther!Form1Subform.Form to refer to the specific instance of
Form1 that is open as a subform on FormOther. As you're probably aware,
in that subform syntax, "Form1Subform" must be the name of the subform
control on the main form, which isn't necessarily the name of Form1
itself.
 
W

Warrio

Thanks a lot Dirk for the clear explanantion!!
I wasn't taking care a lot about Access syntax

Thanks again!
 
Top