ACC: Error "Invalid key" When Adding Node to TreeView Control

Last reviewed: May 7, 1997
Article ID: Q162858
The information in this article applies to:
  • Microsoft Access versions 7.0, 97

SYMPTOMS

Advanced: Requires expert coding, interoperability, and multi-user skills.

When you try to use the Add method of the Node object with the TreeView Custom Control, you may receive the following error message:

   Run-time error '35603':
   Invalid key

NOTE: The TreeView control is only available if you have installed the Microsoft Access Developer's Toolkit version 7.0, or the Office 97 Developer Edition.

CAUSE

The Item Method, which can be used to return a specific member of the Nodes collection, takes one argument. If this argument is a numeric expression, the Item method searches for the Node by index; if the argument is a string expression, the Item method searches for the Node by key. Because this argument is a Variant, the Item method cannot distinguish a key expression from an index expression unless that expression contains at least one non- numeric character.

RESOLUTION

Concatenate at least one non-numeric character to the expression in the key argument of the Add method. For example, add a node by using

   Set Node = Me!CustOrders.Nodes.Add(, , "Node " & rst!OrderID,
   CStr(rst!OrderID))

instead of

   Set Node = Me!CustOrders.Nodes.Add(, , rst!OrderID, CStr(rst!OrderID))

MORE INFORMATION

Steps to Reproduce Behavior

  1. Open the sample database Northwind.mdb.

  2. Create a new form not based on any table or query.

  3. Insert a TreeView Control and name it CustOrders.

  4. Set the form's OnLoad property to the following [Event Procedure]

         Private Sub Form_Load()
    
             Dim db As DATABASE, rst As Recordset
             Dim Node As Object
             Set db = CurrentDb()
             Set rst = db.OpenRecordset("Orders", dbOpenDynaset)
             If rst.RecordCount > 0 Then
                 Do Until rst.EOF
                     Set Node = Me!CustOrders.Nodes.Add(, , _
                             st!OrderID,cstr(rst!OrderID))
                     rst.MoveNext
                 Loop
             End If
             rst.Close
             db.Close
         End Sub
    
    

  5. Open the form in Form View. Note that you receive the following error message:

          Run-time error '35603':
          Invalid Key
    

    The error occurs even if you use the Cstr() function with the key argument (the third argument of the Add method).

REFERENCES

For more information about the Add method of the Node object, search the Help Index for "Add Method," and then "Add Method (Nodes Collection)."

For more information about the Item method, search the Help Index for "Item method."


Keywords : IntpCstm kbcode kberrmsg
Version : 7.0 97
Platform : WINDOWS
Hardware : X86
Issue type : kbprb
Resolution Type : Info_Provided


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 7, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.