odd 'object' error

  • Thread starter Thread starter Ian Mellors
  • Start date Start date
I

Ian Mellors

Hi,

here's the senario

I've got two forms

Edit_Risks1 - Form containing a treeview control. This
control shows documents that are attached to each other.
SafetyCase_document_Attach - Edit form allowing
attachment. This form is displayed by clicking on a node
in the treeview.

In SafetyCase_document_Attach there is the following code

Private Sub Form_Close()
Call Form_Edit_Risks1.NodeRefresh
End Sub

which calls the following in Edit_Risks1

Public Sub NodeRefresh()

If CurrentNode.Children = 0 Then Exit Sub

' Remove current children and re-fill children list
For X = 1 To CurrentNode.Children
TvwObj.Nodes.Remove CurrentNode.child.index
Next
sTag = CurrentNode.Tag
iLevel = Asc(Left(sTag, 1)) - 64

If iLevel < 10 Then Call FillTreeview(CurrentNode,
iLevel + 1)
End Sub

CurrentNode is defined in the declarations section of
Edit_Risks1 and is a copy of the current Node object.

This works great as long as Edit_risks1 is a STAND ALONE
form. However, if the form is then made a sub-form of a
much larger tabbed form (or any other form for that
matter), I get the following error;

Run time error 91
Object variable or With Block variable not set

What's wrong??????
 
When you use this form as a subform, the statement

cant find the Form Edit_Risks1 since a subform is not in the Forms
collection.
Move the code to a standard module, and then call it.

--
Regards,

Adrian Jansen
J & K MicroSystems
Microcomputer solutions for industrial control
 
Thanks Adrian,

if I understand you correctly, I move the whole
NodeRefresh code to a standard module, that's OK, cos I
already have a 'custom' module, where other general forms
code sits.

Question is, how does this code then refer back to the
Edit_Risks1 form? I guess I need to declare the
CurrentNode object in the outside of the form too, but
how does say

If iLevel < 10 Then Call FillTreeview(CurrentNode,iLevel
+ 1)

work, if the code is outside the form, have I got to make
FillTreeview a public function etc, where does it end?
 
Yes, you need to make all the subs/functions called by any function public,
in a code module.

I have fallen into this trap too. But once you realise what you have to do,
its pretty easy, as a matter of coding habit, just put ALL your
subs/functions in code modules, apart from the actual form/report event code
itself.

Meantime you have some cutting and pasting to do..

--
Regards,

Adrian Jansen
J & K MicroSystems
Microcomputer solutions for industrial control
 
dunno, it works for me:

call form_frmCB_Open_sbf.cboAccount_AfterUpdate

frmCB_Open_sbf is a subform on frmCB_Open

Form_frmCB_Open is the code object of the main form:
Form_frmCB_Open_sbf is the code object of the sub form.

The subform is not a member of the forms collection,
but as far as I know, that is not required. Notice
that I am not actually referring to the forms collection
anywhere.

Tested in A97 (private sub) and A2K (public function).

It's not because you are in the Close event is it? Or
just a dodgy corrupt VBA project?

(david)
 
OK, I'll give it a go. I have enough to present the
proposed solution to our Safety Commitee, as soon as I
get the go-ahead, I'll be writing the full system, then
it needs to work!

(watch this space)
 
Weheyy!

I had a spare hour, so I had a go, moved two funtions to
my 'custom' module, (FillTreeView and NodeRefresh) The
only other steps I needed were to move the declarations
of the main treeview object, CurrentNode and the constant
FAKED_CHILD to the cutom module (making sure they were
declared PUBLIC!)

lessons learnt is that any functions that need to be
called from a class object other than the one in which
they reside, must be moved to a public function at module
level.

Luckily, I only had to move two in this case.

Thanks a million Adrian
 
Back
Top