Run Time Error: 91

SSE

New member
Local time
Yesterday, 20:12
Joined
Oct 1, 2012
Messages
4
:banghead:Hi

I got error message in Access Module, hence kindly guide where I doen the mistake.

Error Message:
===========
Run time error '91':
Object Variable or With Block Variable Not Set.

Code:
=====
Public Sub SortNodes(tv As TreeView, Optional blExpand As Boolean)
'Sorts the nodes of the passed tree view
Dim nodNode As Node
Dim X As Integer

Set nodNode = GotoFirstNode(tv) 'tv.Nodes(1)

'Sort the root and nodes
tv.Sorted = True
nodNode.Root.Sorted = True
nodNode.Sorted = True
For X = 1 To tv.Nodes.Count
If tv.Nodes(X).Children > 0 Then
If blExpand = True Then
tv.Nodes(X).Expanded = True
End If
tv.Nodes(X).Sorted = True
End If
Next X

Set nodNode = Nothing
End Sub

Thanks & Regards
SSE :banghead:
 
Hi, and Welcom!

Well, this is one you forget once, and never again... ;)
When you give a value to an object use the Set Key word:
Code:
[B]Set [/B]nodNode.Root.Sorted = True
    [B]Set [/B]nodNode.Sorted = True

Good luck!
 
Hi :banghead:

Thanks for your reply

I am getting Compile Error when using the *Set*

Compile Error:
Invalid use of property

I attached my sample DB, hence kindly check & help me.

Thank in advance.
 

Attachments

You definitely don't need to Set Sorted to True. It's a base type (boolean) so is assigned as you have done.

nodNode.Root.Sorted = True

should work but only if nodNode has actually been assigned to a Node. The error message you got indicates (in VBA's usual clear way) that it hasn't. That at runtime nodNode is Nothing at that point.

So I suspect GotoFirstNode(tv) isn't working at the time (isn't returning a Node).

Where does this code get called? (What event?) I wonder if it's happening before the treeview has any nodes.

Also can you post the code for GotoFirstNode please. I'm not sure why the line isn't just

Set nodNode = tv.Nodes(1)
 
Last edited:
I suspected nodNode.Root is not set, but I was wrong befor, may be wrong again... BTW, in the sample I get a Compiler error, not a runtime. Are You soure Node.Sorted can be updated?
 
Hi Vilarestal

Complete code is available in the earlier attached DB.

Problem is occuring only for this set of value only, remaining are getting through.

I hope problem in the length of the tree view.

Kindly check & revert.
 
Public Function GotoFirstNode(tv As TreeView) As Node
Dim nodNode As Node

Set nodNode = tv.SelectedItem
If nodNode Is Nothing And tv.Nodes.Count > 0 Then
Set nodNode = tv.Nodes.Item(1)
End If

'Goto the root of the current brach
If tv.Nodes.Count > 0 Then
'Set nodNode = nodNode.Root
Do Until nodNode.Parent Is Nothing
Set nodNode = nodNode.Parent
Loop
Do Until nodNode.Previous Is Nothing
Set nodNode = nodNode.Previous
Loop
nodNode.Selected = True
nodNode.EnsureVisible
End If
'Return the result
Set GotoFirstNode = nodNode
End Function
 
Well the version you uploaded on mine crashes (fully kills Access - illegal operation) on the line varNodes.Open in this part of the AddNodes sub:

Code:
    'Test for the type and validity of the source
    Select Case True
        
        Case TypeOf varSource Is ADODB.Recordset, TypeOf varSource Is DAO.Recordset
            Set varNodes = varSource.Clone
            
        Case VarType(varSource) = vbString
            Set varNodes = New ADODB.Recordset
            varNodes.Open varSource, CurrentProject.Connection, adOpenStatic, adLockReadOnly, adCmdText
    
    End Select

so I never get to check the Sorting bit.

It was referencing ADO 2.1, which is pretty old version of it. I tried changing the reference to 2.7. Still crashes. I'm not sure why it's opening an ADODB recordset.

Anyway, I suspect the reason it crashes on mine is because there's no BuildKey function in the database and the SQL (varSource) uses it.

But presumably all that works on yours.

Try just putting

On Error Resume Next

as the first line in the SortNodes sub (and getting rid of the Sets you added) is all I can advise.

In hundreds of lines of code and not one 'On Error' statement. ' Author: Brent Spaulding, datAdrenaline on www.utteraccess.com obviously doesn't believe in error handling.

All this is trying to get a sample Treeview/Listview demo to work? :banghead:
 

Users who are viewing this thread

Back
Top Bottom