PRB: Clone Won't Support All ListFields & ListIndexes Methods

Last reviewed: December 18, 1995
Article ID: Q129286
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic,16-bit and 32-bit, for Windows, version 4.0

SYMPTOMS

The ListFields (Dynaset and Snapshot method) and ListIndexes (Table method) used against a Clone created from a RecordSet object will generate the following error with the Microsoft DAO 3.0 Object Library:

   Function marked as restricted or uses an OLE type not supported in
   Visual Basic

If you chose the Microsoft DAO 2.5/3.0 Compatibility Library and used DynaSet, SnapShot or Table objects, the ListFields and ListIndexes method used against a Clone created from a DynaSet, Snapshot, Table, or RecordSet object will generate this error:

   Run-time error '3251'
   Feature not available

CAUSE

When a Clone is created from any type of RecordSet object, the resulting Clone is a RecordSet object -- not the Visual Basic version 3.0 DynaSet, SnapShot, or Table types. It is not dependent on the type of the object from which it was created. Because the Clone is a RecordSet, only RecordSet properties and methods are available.

RESOLUTION

Visual Basic Version 4.0

The ListFields and ListIndexes methods are included in Visual Basic version 4.0 for compatibility with earlier versions of Visual Basic. For all RecordSet objects, Microsoft recommends that you enumerate the Fields or Indexes collection of the object containing the fields or indexes you want to list.

For Cloned objects, you may need to recode any use of the ListIndexes to enumerate the Fields or Indexes collection of the object. For more information, please see the "Examples of Converting Code to Jet Version 2.5" topic in the Visual Basic version 4.0 Help menu.

Steps to Demonstrate the Correct Alternative to ListFields

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Add a data control (Data1) to Form1.

  3. Set the following properties for Data1.

       Property       Value
       -------------------------
       Databasename   Biblio.MDB
       RecordSource   Authors
    
    

  4. Add the following code to the Form1_Click procedure:

       Sub Form1_Click ()
          Dim RS As RecordSet
          Set RS = Data1.Recordset.Clone()
          For Each Fld In RS.Fields
             Print Fld.Name
          Next
       End Sub
    
    

  5. Start the program by choosing Start from the Run menu or by pressing the F5 key.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior in Visual Basic

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Add a data control (Data1) to Form1.

  3. Set the following properties for Data1:

       Property       Value
       -------------------------
       Databasename   Biblio.MDB
       RecordSource   Authors
    
    

  4. Add the following code to the Form1_Click procedure:

       Sub Form1_Click ()
          Dim DS As Dynaset, LF As Snapshot
          Set DS = Data1.Recordset.Clone()
          Set LF = DS.Listfields()
          While Not LF.EOF()
             Print LF("name")
             LF.Movenext
          Wend
       End Sub
    
    

  5. Start the program by choosing Start from the Run menu or by pressing the F5 key.

Depending on which DAO Reference you chose under Tools References, you will get one of the two errors mentioned above.


Additional reference words: 4.00 vb4win vb4all
KBCategory: kbprg kbprb
KBSubcategory: APrgData APrgDataOther


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: December 18, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.