Microsoft Office 2000 Developer   

Displaying a Hierarchical FlexGrid on an Access Form

See Also

If you want to take advantage of the hierarchical features of the Hierarchical FlexGrid control on an Access form, you must create a data source that returns a hierarchical cursor. This can be done most easily by compiling the Data Environment designer as a DLL file. The DLL then becomes the data source.

Note   The control does work properly with a standard recordset, it just does not use any of the hierarchical features of the grid.

It's also possible to create a hierarchical cursor by setting the RecordSource of an ADO Data Control or the Source property of an ADO Recordset object to a Shape command. See Shape Commands in General for an introduction.

Note   Because the Hierarchical FlexGrid cannot be bound at design time to a data source, the Retrieve Structure command will fail.

To display a Hierarchical FlexGrid control on an Access form

  1. Configure a Data Environment. For this example, name the DataEnvironment object "deNwind."

    For information about setting up a Data Environment as a data source, see Inserting ActiveX Designers into a Visual Basic Editor Project.

  2. Add a public function to return recordsets from the DataEnvironment object, and compile the project as a DLL file. For this example, name the DLL file "prjDE."

    For information on compiling the DataEnvironment object, see Creating a DataEnvironment Object for Use in a DLL File.

  3. Draw a Hierarchical FlexGrid control on an Access form. See Activating and Inserting Controls for information.

  4. Rename the Hierarchical FlexGrid control to "myFlexGrid."

  5. Draw a command button control onto the form, and set its Caption property to Bind.

  6. Right-click the command button control, and click Build Event. Double-click Code Builder. The Visual Basic Editor should open.

  7. On the Tools menu, click References.

  8. In the References dialog box, find the name of the DLL that contains the Data Environment. Check the DLL name, and close the dialog box.

  9. In the code window, paste the following code:
    Option Compare Database
    Option Explicit
    ' Assuming the name of the DLL is prjDE, and the name of the 
    ' DataEnvironment object is deNwind.
    Private myDE As deNwind.DataEnvironment1
    
    Private Sub Command1_Click()
       Set myDE = New deNwind.DataEnvironment1
       Dim myGrid As MSHFlexGrid
       Set myGrid = myFlexGrid.Object
       ' The DataEnvironment object compiled in the DLL has a function
       ' named ThisRS. It takes one argument, the name of the table
       ' desired, and returns the recordset.
       Set myGrid.DataSource = myDE.ReturnRS("Customers")
    End Sub
    
  10. On the Run menu, click Design Mode.

  11. Switch to the Access form.

  12. On the View menu, click Form View.

  13. Click the Bind button.