Method Item of Object Forms Failed

  • Thread starter robert d via AccessMonster.com
  • Start date
R

robert d via AccessMonster.com

I have a form that shows the history of a project. This history form can be
opened from a number of other forms. The form that calls the history form
sets a global variable:

CallingProposalForm = Me.Name

In a non-form code module I have the following:

Public CallingProposalForm As String


When the history form opens, the following line of code executes and this is
the one experiencing the problem:

If Nz(Forms(CallingProposalForm).Parse0, "") <> "(All)" Then

Parse0 is a hidden textbox on CallingProposalForm that contains the selection
made from a Treeview on that form. The value of Parse0 tells the history
form what to display.

When the code breaks on this line, I can clearly see that the value of
CallingProposalForm is correct. Parse0 is definately a hidden textbox on
the calling form.

I'm wondering if the problem occurs because the global module is defined as a
String. Do I instead need to define it as a forms object. I could test this
but I' m looking for advice on a good practice for handling passing form
names from one form to another.

Thanks.
 
K

Ken Snell \(MVP\)

You appear to have set up the code steps correctly. You would want to use a
String variable for CallingProposalForm.

I do not typically use global variables for such purposes, though, as it's
much easier to use the OpenArgs argument of the DoCmd.OpenForm method to
pass the type of information from one form to another. I especially use this
technique to pass the name of the calling form to the form that is being
opened.

In your calling form's code that opens the new form, use the OpenArgs
argument to pass the name of the calling form:

DoCmd.OpenForm "NameOfFormBeingOpened", OpenArgs:=Me.Name

Then, in the Load event of the opened form, use the OpenArgs property to get
the name of the calling form:

Private Sub Form_Load()
If Nz(Forms(Me.OpenArgs).Parse0, "") <> "(All)" Then
' etc.
End Sub
 
R

robert d via AccessMonster.com

Thanks, Ken.

Yes, I have way too many global variables and only today took the time to try
and understand the OpenArgs argument. I had intended to use it for this
particular form.

What I failed to mention, is that the history form has a subform on it and
the line of code experiencing the problem is actually in the subform. The
subform container on the history form can load a number of different subforms.


I'm currently using the following to set the subform
Me("ECMSubform1").SourceObject = "SubForm1"

The subform container SourceObject is not supposed to be set in the
properties datasheet, but somehow was (probably during a save operation
during coding changes). This is what caused the error and that error is now
gone.

But because I'm setting the subform this way and not using DoCmd.OpenForm,
how can I use the OpenArgs option.

Thanks.
You appear to have set up the code steps correctly. You would want to use a
String variable for CallingProposalForm.

I do not typically use global variables for such purposes, though, as it's
much easier to use the OpenArgs argument of the DoCmd.OpenForm method to
pass the type of information from one form to another. I especially use this
technique to pass the name of the calling form to the form that is being
opened.

In your calling form's code that opens the new form, use the OpenArgs
argument to pass the name of the calling form:

DoCmd.OpenForm "NameOfFormBeingOpened", OpenArgs:=Me.Name

Then, in the Load event of the opened form, use the OpenArgs property to get
the name of the calling form:

Private Sub Form_Load()
If Nz(Forms(Me.OpenArgs).Parse0, "") <> "(All)" Then
' etc.
End Sub
I have a form that shows the history of a project. This history form can
be
[quoted text clipped - 30 lines]
 
K

Ken Snell \(MVP\)

I'm sorry, but I don't understand your database setup well enough to know
what the "history" form is.. is that the calling form or the called form?

Is the Parse0 textbox on a main form or in a subform?

Let's start at the beginning and provide some details about the forms and
subforms, which ones call which, what you are doing based on the value of
Parse0 textbox on a form, etc. We need to "see" your database (based on your
description) so that we can understand the flow and logic.

--

Ken Snell
<MS ACCESS MVP>

robert d via AccessMonster.com said:
Thanks, Ken.

Yes, I have way too many global variables and only today took the time to
try
and understand the OpenArgs argument. I had intended to use it for this
particular form.

What I failed to mention, is that the history form has a subform on it and
the line of code experiencing the problem is actually in the subform. The
subform container on the history form can load a number of different
subforms.


I'm currently using the following to set the subform
Me("ECMSubform1").SourceObject = "SubForm1"

The subform container SourceObject is not supposed to be set in the
properties datasheet, but somehow was (probably during a save operation
during coding changes). This is what caused the error and that error is
now
gone.

But because I'm setting the subform this way and not using DoCmd.OpenForm,
how can I use the OpenArgs option.

Thanks.
You appear to have set up the code steps correctly. You would want to use
a
String variable for CallingProposalForm.

I do not typically use global variables for such purposes, though, as it's
much easier to use the OpenArgs argument of the DoCmd.OpenForm method to
pass the type of information from one form to another. I especially use
this
technique to pass the name of the calling form to the form that is being
opened.

In your calling form's code that opens the new form, use the OpenArgs
argument to pass the name of the calling form:

DoCmd.OpenForm "NameOfFormBeingOpened", OpenArgs:=Me.Name

Then, in the Load event of the opened form, use the OpenArgs property to
get
the name of the calling form:

Private Sub Form_Load()
If Nz(Forms(Me.OpenArgs).Parse0, "") <> "(All)" Then
' etc.
End Sub
I have a form that shows the history of a project. This history form can
be
[quoted text clipped - 30 lines]
 
R

robert d via AccessMonster.com

Okay:

Three forms:

-- Project form
-- Project History form (called History form in previous posts)
-- Subform to be brought up in Project History form

Project form has a button to load the Project History form. When this button
is clicked the CallingProposalForm is set to "Project History" and not
"Project". Why, because I want the subform to be loaded with the correct
data when the Project History form loads.

I pass the Project Name to be shown on the Project History form via the
OpenArgs of DoCmd.OpenForm. This opens the Project History form, but does
not automatically load the subform for Project History form.

Parse0 is a text field on the Project History form and is to be used by the
subform control to know which subform to display . In a nutshell, the
Project History form has seven trees on it. with seven corresponding subform
controls. This allows one to see the history of the project based on its
Status (Pending, Approved, Installed, etc) and status date. You click on a
node in any tree and code loads the appropriate subform into the
corresponding tree subform container which provides the information for that
specific node in that specific tree. Any trees or subforms that are not
filled are hidden.

Everything is working fine now (the original error has been fixed). My only
question now is how do I pass the name of the form (CallingProposalForm) that
contains the text, Parse0, to the subform.

One last point is that these same subforms are used not only on the Project
History form but on the Project form and another form. That's why the subform
needs to know who called it because it needs to know which form to get Parse0
from (All three forms have a hidden textbox called Parse0).

As far as I can tell: Setting the SourceObject of a subform container does
not give you the opportunity to specify something similar to OpenArgs. Hence,
I have to use global variable to specify which form.

Everything is working, I was just wondering if there is a way to get around
passing a global variable for the form name (CallingProposalForm).

Thanks.



I'm sorry, but I don't understand your database setup well enough to know
what the "history" form is.. is that the calling form or the called form?

Is the Parse0 textbox on a main form or in a subform?

Let's start at the beginning and provide some details about the forms and
subforms, which ones call which, what you are doing based on the value of
Parse0 textbox on a form, etc. We need to "see" your database (based on your
description) so that we can understand the flow and logic.
Thanks, Ken.
[quoted text clipped - 51 lines]
 
K

Ken Snell \(MVP\)

Because you do not "load" the subform as part of the "history" form's
initial load (meaning, the subform control's SourceObject is set by the
"history" form after it opens), you could have the subform read the
"history" form's OpenArgs argument in this way:

NameOfCallingForm = Me.Parent.OpenArgs

Parent is a property that allows the subform to read data from its parent
main form.

If the subform control's SourceObject were "hard-coded" as part of the
form's design, and you were to try to read the parent's OpenArgs property in
the subform's Load event, likely the code would "error" because subforms are
loaded prior to the main form when a new form is being opened. But, once the
main form is loaded, its properties then are available for the subform to
read.

--

Ken Snell
<MS ACCESS MVP>

robert d via AccessMonster.com said:
Okay:

Three forms:

-- Project form
-- Project History form (called History form in previous posts)
-- Subform to be brought up in Project History form

Project form has a button to load the Project History form. When this
button
is clicked the CallingProposalForm is set to "Project History" and not
"Project". Why, because I want the subform to be loaded with the correct
data when the Project History form loads.

I pass the Project Name to be shown on the Project History form via the
OpenArgs of DoCmd.OpenForm. This opens the Project History form, but does
not automatically load the subform for Project History form.

Parse0 is a text field on the Project History form and is to be used by
the
subform control to know which subform to display . In a nutshell, the
Project History form has seven trees on it. with seven corresponding
subform
controls. This allows one to see the history of the project based on its
Status (Pending, Approved, Installed, etc) and status date. You click on
a
node in any tree and code loads the appropriate subform into the
corresponding tree subform container which provides the information for
that
specific node in that specific tree. Any trees or subforms that are not
filled are hidden.

Everything is working fine now (the original error has been fixed). My
only
question now is how do I pass the name of the form (CallingProposalForm)
that
contains the text, Parse0, to the subform.

One last point is that these same subforms are used not only on the
Project
History form but on the Project form and another form. That's why the
subform
needs to know who called it because it needs to know which form to get
Parse0
from (All three forms have a hidden textbox called Parse0).

As far as I can tell: Setting the SourceObject of a subform container
does
not give you the opportunity to specify something similar to OpenArgs.
Hence,
I have to use global variable to specify which form.

Everything is working, I was just wondering if there is a way to get
around
passing a global variable for the form name (CallingProposalForm).

Thanks.



I'm sorry, but I don't understand your database setup well enough to know
what the "history" form is.. is that the calling form or the called form?

Is the Parse0 textbox on a main form or in a subform?

Let's start at the beginning and provide some details about the forms and
subforms, which ones call which, what you are doing based on the value of
Parse0 textbox on a form, etc. We need to "see" your database (based on
your
description) so that we can understand the flow and logic.
Thanks, Ken.
[quoted text clipped - 51 lines]
 

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