Referencing subform in code

P

Paul

Hi

I have an 'agreement' form where the subform 'source object' can be changed
dynamically to one of six different 'agreement detail' forms.

I want to reference the code on the subform (all six forms contain this
code, but I need to call the code on the subform that is showing).

The subform control is named sbfrmAgreementDetails,

I have tried: Me.sbfrmAgreementDetails.Form.Form_Resize

However, because the name of the subform control does not match the name of
the sourceobject form, this code does not work.

The form that is the source object could be:

sbfrmAgreementDetailSafety, or
sbfrmAgreementDetailLogitstics, or
sbfrmAgreementDetailDistribution, etc

depending on the type of agreement selected in the main form.

I can't seem to get the syntax right to call the Form_Resize event of the
form specified in the SourceObject property of the subform.

I hope the above is clear! Can anyone suggest a solution?

Thanks

Paul
 
V

Van T. Dinh

1. I am not sure whether the Form_Resize Event actually fires when the Form
is being used as the SourceObject of a Subform Control since AFAIK, we don't
have the "Restored" state (or "Minimized" state) for the SourceObject. It
is not entirely "Maximized" either.

2. (Regardless of 1), have you checked that the Form_Resize Event
procedures are declared as Public rather than Private? You will need them
to be Public if you want to call them from outside the Form being used as
the SourceObject.
 
P

Paul

Hi,

Thanks for response.

Point 1: This is code I have used routinely on subforms for many years. When
a subform is resized as a result of the parent being resized, the resize
event does not fire, but this code forces it to. There are actually two
other small subforms on this form and they use the code and work fine.

Point 2: The subform I am trying to reference contains exactly the same code
as the other subforms (which i can reference OK and are working fine) so I
don't think this is an issue.

My problem is simply how do I instruct the code on the subform fire?

The syntax Forms![Parent form]![Child form].form does not work as I cannot
pass a string as the child form name in this syntax. Not sure if the eval
function might prove useful here?!?

Thanks

Paul
 
D

Dan Artuso

Hi,
Yes, you can pass a string:

Forms("parentForm")("childFormName")

--
HTH
Dan Artuso, Access MVP


Paul said:
Hi,

Thanks for response.

Point 1: This is code I have used routinely on subforms for many years. When
a subform is resized as a result of the parent being resized, the resize
event does not fire, but this code forces it to. There are actually two
other small subforms on this form and they use the code and work fine.

Point 2: The subform I am trying to reference contains exactly the same code
as the other subforms (which i can reference OK and are working fine) so I
don't think this is an issue.

My problem is simply how do I instruct the code on the subform fire?

The syntax Forms![Parent form]![Child form].form does not work as I cannot
pass a string as the child form name in this syntax. Not sure if the eval
function might prove useful here?!?

Thanks

Paul

Van T. Dinh said:
1. I am not sure whether the Form_Resize Event actually fires when the
Form
is being used as the SourceObject of a Subform Control since AFAIK, we
don't
have the "Restored" state (or "Minimized" state) for the SourceObject. It
is not entirely "Maximized" either.

2. (Regardless of 1), have you checked that the Form_Resize Event
procedures are declared as Public rather than Private? You will need them
to be Public if you want to call them from outside the Form being used as
the SourceObject.
 
V

Van T. Dinh

Thanks, Paul

What you wrote in point 1 actually confirms what I suspected: The Resize
Event doesn't happen. You could name the Sub any name and simply call it
using the appropriate name, not just "Form_Resize".

For point 2, I am not sure what you described here. From your original
post, I thought that you want to call (& execute) a Sub in the SourceObject
with the call originates from the Main Form. You previously mentioned that
the SourceObject can be one of the set of 6 Forms. In your reply to point
2, you mentioned "...the other subforms (which i can reference OK and are
working fine) ...".

Do you mean you use the same Call statement and for 5 SourceObject Forms,
the call worked fine and the 6th SourceObject Form doesn't work as you
expected?

It helps if you post the relevant code and the Call statement ...
 
P

Paul

Hi,

Sorry - I'm trying to be brief and causing confusion.

I regularly use me.subform.form.form_resize to trigger the resize event of a
subform (as it is not *automatically* triggered when the subform control's
hieght and width are dynamically modified. In my case the code that changes
the hieght/width of the subform control is triggered by the resize event of
the main form).

On my main form I actually have three subforms. There are two where I use my
normal technique (me.subform.form.form_resize) to call code in the resize
event of the subform.

The third subform can actually be any one of six forms (depending on the
data entered in the main form). I set the controlsource property of this
subform dynamically by setting the ControlSource property to the appropriate
form.

My issue is that I cannot use my normal syntax to call the resize event in
this case. If I use the *name* of the subform control I get an error
(because Access looks for a form of this name to get the form_resize code
and there is no form with this name). I am having trouble with the syntax of
calling code in a form when that form is a subform and when I need to refer
to the form using a string rather than a hardcoded form name.

For example:

me.subformcontrol.controlsource.form.form_resize - this cleary won't work,
form is not a property of controlsource.

me.controls(subformcontrol.controlsource).form.form_resize - this is wrong
because there is no *control* with this name (subformcontrol.controlsource)
is the name of the form that is the source for the control).

forms!MainForm!ChildForm.form_resize - doesn't seem to accept an evaluated
value or string variable in the place of ChildForm, as in
Forms!MainForm!(me.subform.controlsource).form.form_resize

I hope that makes things a little clearer.

Thanks

Paul

Van T. Dinh said:
Thanks, Paul

What you wrote in point 1 actually confirms what I suspected: The Resize
Event doesn't happen. You could name the Sub any name and simply call it
using the appropriate name, not just "Form_Resize".

For point 2, I am not sure what you described here. From your original
post, I thought that you want to call (& execute) a Sub in the
SourceObject
with the call originates from the Main Form. You previously mentioned
that
the SourceObject can be one of the set of 6 Forms. In your reply to point
2, you mentioned "...the other subforms (which i can reference OK and are
working fine) ...".

Do you mean you use the same Call statement and for 5 SourceObject Forms,
the call worked fine and the 6th SourceObject Form doesn't work as you
expected?

It helps if you post the relevant code and the Call statement ...

--
HTH
Van T. Dinh
MVP (Access)




Paul said:
Hi,

Thanks for response.

Point 1: This is code I have used routinely on subforms for many years. When
a subform is resized as a result of the parent being resized, the resize
event does not fire, but this code forces it to. There are actually two
other small subforms on this form and they use the code and work fine.

Point 2: The subform I am trying to reference contains exactly the same code
as the other subforms (which i can reference OK and are working fine) so
I
don't think this is an issue.

My problem is simply how do I instruct the code on the subform fire?

The syntax Forms![Parent form]![Child form].form does not work as I
cannot
pass a string as the child form name in this syntax. Not sure if the eval
function might prove useful here?!?

Thanks

Paul
 
P

Paul

Sorry - in all cases below where I refer to ControlSource I of course should
have said SourceObject.

Paul said:
Hi,

Sorry - I'm trying to be brief and causing confusion.

I regularly use me.subform.form.form_resize to trigger the resize event of
a subform (as it is not *automatically* triggered when the subform
control's hieght and width are dynamically modified. In my case the code
that changes the hieght/width of the subform control is triggered by the
resize event of the main form).

On my main form I actually have three subforms. There are two where I use
my normal technique (me.subform.form.form_resize) to call code in the
resize event of the subform.

The third subform can actually be any one of six forms (depending on the
data entered in the main form). I set the controlsource property of this
subform dynamically by setting the ControlSource property to the
appropriate form.

My issue is that I cannot use my normal syntax to call the resize event in
this case. If I use the *name* of the subform control I get an error
(because Access looks for a form of this name to get the form_resize code
and there is no form with this name). I am having trouble with the syntax
of calling code in a form when that form is a subform and when I need to
refer to the form using a string rather than a hardcoded form name.

For example:

me.subformcontrol.controlsource.form.form_resize - this cleary won't work,
form is not a property of controlsource.

me.controls(subformcontrol.controlsource).form.form_resize - this is wrong
because there is no *control* with this name
(subformcontrol.controlsource) is the name of the form that is the source
for the control).

forms!MainForm!ChildForm.form_resize - doesn't seem to accept an evaluated
value or string variable in the place of ChildForm, as in
Forms!MainForm!(me.subform.controlsource).form.form_resize

I hope that makes things a little clearer.

Thanks

Paul

Van T. Dinh said:
Thanks, Paul

What you wrote in point 1 actually confirms what I suspected: The Resize
Event doesn't happen. You could name the Sub any name and simply call it
using the appropriate name, not just "Form_Resize".

For point 2, I am not sure what you described here. From your original
post, I thought that you want to call (& execute) a Sub in the
SourceObject
with the call originates from the Main Form. You previously mentioned
that
the SourceObject can be one of the set of 6 Forms. In your reply to
point
2, you mentioned "...the other subforms (which i can reference OK and are
working fine) ...".

Do you mean you use the same Call statement and for 5 SourceObject Forms,
the call worked fine and the 6th SourceObject Form doesn't work as you
expected?

It helps if you post the relevant code and the Call statement ...

--
HTH
Van T. Dinh
MVP (Access)




Paul said:
Hi,

Thanks for response.

Point 1: This is code I have used routinely on subforms for many years. When
a subform is resized as a result of the parent being resized, the resize
event does not fire, but this code forces it to. There are actually two
other small subforms on this form and they use the code and work fine.

Point 2: The subform I am trying to reference contains exactly the same code
as the other subforms (which i can reference OK and are working fine) so
I
don't think this is an issue.

My problem is simply how do I instruct the code on the subform fire?

The syntax Forms![Parent form]![Child form].form does not work as I
cannot
pass a string as the child form name in this syntax. Not sure if the
eval
function might prove useful here?!?

Thanks

Paul
 
P

Paul

Thank you, but you suggestion doesnt seem to be working.

The following is from the debug window:

?forms!frmagreement!sbfrmAgreementTerritory.name

?Forms!frmagreement!(Me.sbfrmAgreementDetails.SourceObject).name

?Forms("frmAgreement")(Me.sbfrmAgreementDetails.SourceObject).name

The first of these lines runs fine (in this case the name of the subform
control and of the SourceObject match - normal setup).

The second two try to pull the name property of the form used as the
SourceObject for the sbfrmAgreementDetails subform control (just so I can
test the referencing syntax). Code elsewhere in my system can change the
SourceObject for this subform control. Neither of these lines work.

They both give error 2465 - "...can't find the field
'sbfrmAgreementDetailSafety' referred to..."

sbfrmAgreementDetailSafety is the form that is the SourceObject for
sbfrmAgreementDetails (this time, other code can change the SourceObject to
one of six different forms). All six forms that can be the SourceObject
contain code in Form_Resize. I need to run this code.

Any ideas?

Thanks

Paul


Dan Artuso said:
Hi,
Yes, you can pass a string:

Forms("parentForm")("childFormName")

--
HTH
Dan Artuso, Access MVP


Paul said:
Hi,

Thanks for response.

Point 1: This is code I have used routinely on subforms for many years.
When
a subform is resized as a result of the parent being resized, the resize
event does not fire, but this code forces it to. There are actually two
other small subforms on this form and they use the code and work fine.

Point 2: The subform I am trying to reference contains exactly the same
code
as the other subforms (which i can reference OK and are working fine) so
I
don't think this is an issue.

My problem is simply how do I instruct the code on the subform fire?

The syntax Forms![Parent form]![Child form].form does not work as I
cannot
pass a string as the child form name in this syntax. Not sure if the eval
function might prove useful here?!?

Thanks

Paul

Van T. Dinh said:
1. I am not sure whether the Form_Resize Event actually fires when the
Form
is being used as the SourceObject of a Subform Control since AFAIK, we
don't
have the "Restored" state (or "Minimized" state) for the SourceObject.
It
is not entirely "Maximized" either.

2. (Regardless of 1), have you checked that the Form_Resize Event
procedures are declared as Public rather than Private? You will need
them
to be Public if you want to call them from outside the Form being used
as
the SourceObject.

--
HTH
Van T. Dinh
MVP (Access)





Hi

I have an 'agreement' form where the subform 'source object' can be
changed
dynamically to one of six different 'agreement detail' forms.

I want to reference the code on the subform (all six forms contain
this
code, but I need to call the code on the subform that is showing).

The subform control is named sbfrmAgreementDetails,

I have tried: Me.sbfrmAgreementDetails.Form.Form_Resize

However, because the name of the subform control does not match the
name
of
the sourceobject form, this code does not work.

The form that is the source object could be:

sbfrmAgreementDetailSafety, or
sbfrmAgreementDetailLogitstics, or
sbfrmAgreementDetailDistribution, etc

depending on the type of agreement selected in the main form.

I can't seem to get the syntax right to call the Form_Resize event of
the
form specified in the SourceObject property of the subform.

I hope the above is clear! Can anyone suggest a solution?

Thanks

Paul
 
P

Paul

Never mind - I've found what I need:

Me.Controls("sbfrmAgreementDetails").Form.form_resize

The above works just fine regardless of which actual form is specified as
the SourceObject.


Paul said:
Sorry - in all cases below where I refer to ControlSource I of course
should have said SourceObject.

Paul said:
Hi,

Sorry - I'm trying to be brief and causing confusion.

I regularly use me.subform.form.form_resize to trigger the resize event
of a subform (as it is not *automatically* triggered when the subform
control's hieght and width are dynamically modified. In my case the code
that changes the hieght/width of the subform control is triggered by the
resize event of the main form).

On my main form I actually have three subforms. There are two where I use
my normal technique (me.subform.form.form_resize) to call code in the
resize event of the subform.

The third subform can actually be any one of six forms (depending on the
data entered in the main form). I set the controlsource property of this
subform dynamically by setting the ControlSource property to the
appropriate form.

My issue is that I cannot use my normal syntax to call the resize event
in this case. If I use the *name* of the subform control I get an error
(because Access looks for a form of this name to get the form_resize code
and there is no form with this name). I am having trouble with the syntax
of calling code in a form when that form is a subform and when I need to
refer to the form using a string rather than a hardcoded form name.

For example:

me.subformcontrol.controlsource.form.form_resize - this cleary won't
work, form is not a property of controlsource.

me.controls(subformcontrol.controlsource).form.form_resize - this is
wrong because there is no *control* with this name
(subformcontrol.controlsource) is the name of the form that is the source
for the control).

forms!MainForm!ChildForm.form_resize - doesn't seem to accept an
evaluated value or string variable in the place of ChildForm, as in
Forms!MainForm!(me.subform.controlsource).form.form_resize

I hope that makes things a little clearer.

Thanks

Paul

Van T. Dinh said:
Thanks, Paul

What you wrote in point 1 actually confirms what I suspected: The Resize
Event doesn't happen. You could name the Sub any name and simply call
it
using the appropriate name, not just "Form_Resize".

For point 2, I am not sure what you described here. From your original
post, I thought that you want to call (& execute) a Sub in the
SourceObject
with the call originates from the Main Form. You previously mentioned
that
the SourceObject can be one of the set of 6 Forms. In your reply to
point
2, you mentioned "...the other subforms (which i can reference OK and
are
working fine) ...".

Do you mean you use the same Call statement and for 5 SourceObject
Forms,
the call worked fine and the 6th SourceObject Form doesn't work as you
expected?

It helps if you post the relevant code and the Call statement ...

--
HTH
Van T. Dinh
MVP (Access)




Hi,

Thanks for response.

Point 1: This is code I have used routinely on subforms for many years.
When
a subform is resized as a result of the parent being resized, the
resize
event does not fire, but this code forces it to. There are actually two
other small subforms on this form and they use the code and work fine.

Point 2: The subform I am trying to reference contains exactly the same
code
as the other subforms (which i can reference OK and are working fine)
so I
don't think this is an issue.

My problem is simply how do I instruct the code on the subform fire?

The syntax Forms![Parent form]![Child form].form does not work as I
cannot
pass a string as the child form name in this syntax. Not sure if the
eval
function might prove useful here?!?

Thanks

Paul
 
D

Dan Artuso

Hi,
First off, Me will not work from the debug window.
The syntax does work.
In my sample db I have a subform control called frmDatasheet with a source object
of datasheet (different names).
From the debug window:

?Forms("frmMain1")("frmDatasheet").SourceObject
Datasheet

--
HTH
Dan Artuso, Access MVP


Paul said:
Thank you, but you suggestion doesnt seem to be working.

The following is from the debug window:

?forms!frmagreement!sbfrmAgreementTerritory.name

?Forms!frmagreement!(Me.sbfrmAgreementDetails.SourceObject).name

?Forms("frmAgreement")(Me.sbfrmAgreementDetails.SourceObject).name

The first of these lines runs fine (in this case the name of the subform
control and of the SourceObject match - normal setup).

The second two try to pull the name property of the form used as the
SourceObject for the sbfrmAgreementDetails subform control (just so I can
test the referencing syntax). Code elsewhere in my system can change the
SourceObject for this subform control. Neither of these lines work.

They both give error 2465 - "...can't find the field
'sbfrmAgreementDetailSafety' referred to..."

sbfrmAgreementDetailSafety is the form that is the SourceObject for
sbfrmAgreementDetails (this time, other code can change the SourceObject to
one of six different forms). All six forms that can be the SourceObject
contain code in Form_Resize. I need to run this code.

Any ideas?

Thanks

Paul


Dan Artuso said:
Hi,
Yes, you can pass a string:

Forms("parentForm")("childFormName")

--
HTH
Dan Artuso, Access MVP


Paul said:
Hi,

Thanks for response.

Point 1: This is code I have used routinely on subforms for many years.
When
a subform is resized as a result of the parent being resized, the resize
event does not fire, but this code forces it to. There are actually two
other small subforms on this form and they use the code and work fine.

Point 2: The subform I am trying to reference contains exactly the same
code
as the other subforms (which i can reference OK and are working fine) so
I
don't think this is an issue.

My problem is simply how do I instruct the code on the subform fire?

The syntax Forms![Parent form]![Child form].form does not work as I
cannot
pass a string as the child form name in this syntax. Not sure if the eval
function might prove useful here?!?

Thanks

Paul

1. I am not sure whether the Form_Resize Event actually fires when the
Form
is being used as the SourceObject of a Subform Control since AFAIK, we
don't
have the "Restored" state (or "Minimized" state) for the SourceObject.
It
is not entirely "Maximized" either.

2. (Regardless of 1), have you checked that the Form_Resize Event
procedures are declared as Public rather than Private? You will need
them
to be Public if you want to call them from outside the Form being used
as
the SourceObject.

--
HTH
Van T. Dinh
MVP (Access)





Hi

I have an 'agreement' form where the subform 'source object' can be
changed
dynamically to one of six different 'agreement detail' forms.

I want to reference the code on the subform (all six forms contain
this
code, but I need to call the code on the subform that is showing).

The subform control is named sbfrmAgreementDetails,

I have tried: Me.sbfrmAgreementDetails.Form.Form_Resize

However, because the name of the subform control does not match the
name
of
the sourceobject form, this code does not work.

The form that is the source object could be:

sbfrmAgreementDetailSafety, or
sbfrmAgreementDetailLogitstics, or
sbfrmAgreementDetailDistribution, etc

depending on the type of agreement selected in the main form.

I can't seem to get the syntax right to call the Form_Resize event of
the
form specified in the SourceObject property of the subform.

I hope the above is clear! Can anyone suggest a solution?

Thanks

Paul
 
P

Paul

Hi,

Me does work in the debug window if you are in break mode (as I was).

I have found that the following syntax:

Me.Controls("sbfrmAgreementDetails").Form.form_resize

works just fine regardless of which actual form is specified as
the SourceObject.

The problem I had with your suggested syntax was that when the
"frmDataSheet" (subform) part was replaced with string/evaulation returning
the name, it did not work for me (Access 2003 - I didn't try in any other
versions).

Thanks

Paul


Dan Artuso said:
Hi,
First off, Me will not work from the debug window.
The syntax does work.
In my sample db I have a subform control called frmDatasheet with a source
object
of datasheet (different names).
From the debug window:

?Forms("frmMain1")("frmDatasheet").SourceObject
Datasheet

--
HTH
Dan Artuso, Access MVP


Paul said:
Thank you, but you suggestion doesnt seem to be working.

The following is from the debug window:

?forms!frmagreement!sbfrmAgreementTerritory.name

?Forms!frmagreement!(Me.sbfrmAgreementDetails.SourceObject).name

?Forms("frmAgreement")(Me.sbfrmAgreementDetails.SourceObject).name

The first of these lines runs fine (in this case the name of the subform
control and of the SourceObject match - normal setup).

The second two try to pull the name property of the form used as the
SourceObject for the sbfrmAgreementDetails subform control (just so I can
test the referencing syntax). Code elsewhere in my system can change the
SourceObject for this subform control. Neither of these lines work.

They both give error 2465 - "...can't find the field
'sbfrmAgreementDetailSafety' referred to..."

sbfrmAgreementDetailSafety is the form that is the SourceObject for
sbfrmAgreementDetails (this time, other code can change the SourceObject
to
one of six different forms). All six forms that can be the SourceObject
contain code in Form_Resize. I need to run this code.

Any ideas?

Thanks

Paul


Dan Artuso said:
Hi,
Yes, you can pass a string:

Forms("parentForm")("childFormName")

--
HTH
Dan Artuso, Access MVP


Hi,

Thanks for response.

Point 1: This is code I have used routinely on subforms for many
years.
When
a subform is resized as a result of the parent being resized, the
resize
event does not fire, but this code forces it to. There are actually
two
other small subforms on this form and they use the code and work fine.

Point 2: The subform I am trying to reference contains exactly the
same
code
as the other subforms (which i can reference OK and are working fine)
so
I
don't think this is an issue.

My problem is simply how do I instruct the code on the subform fire?

The syntax Forms![Parent form]![Child form].form does not work as I
cannot
pass a string as the child form name in this syntax. Not sure if the
eval
function might prove useful here?!?

Thanks

Paul

message
1. I am not sure whether the Form_Resize Event actually fires when
the
Form
is being used as the SourceObject of a Subform Control since AFAIK,
we
don't
have the "Restored" state (or "Minimized" state) for the
SourceObject.
It
is not entirely "Maximized" either.

2. (Regardless of 1), have you checked that the Form_Resize Event
procedures are declared as Public rather than Private? You will
need
them
to be Public if you want to call them from outside the Form being
used
as
the SourceObject.

--
HTH
Van T. Dinh
MVP (Access)





Hi

I have an 'agreement' form where the subform 'source object' can be
changed
dynamically to one of six different 'agreement detail' forms.

I want to reference the code on the subform (all six forms contain
this
code, but I need to call the code on the subform that is showing).

The subform control is named sbfrmAgreementDetails,

I have tried: Me.sbfrmAgreementDetails.Form.Form_Resize

However, because the name of the subform control does not match the
name
of
the sourceobject form, this code does not work.

The form that is the source object could be:

sbfrmAgreementDetailSafety, or
sbfrmAgreementDetailLogitstics, or
sbfrmAgreementDetailDistribution, etc

depending on the type of agreement selected in the main form.

I can't seem to get the syntax right to call the Form_Resize event
of
the
form specified in the SourceObject property of the subform.

I hope the above is clear! Can anyone suggest a solution?

Thanks

Paul
 

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