Step 2: Initialize the Main List Box

Microsoft ActiveX Data Objects (ADO)

Step 2: Initialize the Main List Box

To declare global Record and Recordset objects

  • Insert the following code into the (General) (Declarations) for Form1:
    Option Explicit
    Dim grec As Record
    Dim grs As Recordset
    

    This code declares global object references for Record and Recordset that will be used later in this scenario.

To connect to a URL and populate lstMain

  • Insert the following code into the Form Load event handler for Form1:
    Private Sub Form_Load()
        Set grec = New Record
        Set grs = New Recordset
        grec.Open "", "URL=http://servername/foldername/", , _
            adOpenIfExists Or adCreateCollection
        Set grs = grec.GetChildren
        While Not grs.EOF
            lstMain.AddItem grs(0)
            grs.MoveNext
        Wend
    End Sub
    

    This code instantiates the global Record and Recordset objects. The Record, grec, is opened with a URL specified as the ActiveConnection. If the URL exists, it is opened; if it doesn't already exist, it is created. Note that you should replace "http://servername/foldername/" with a valid URL from your environment.

    The Recordset, grs, is opened on the children of the Record, grec. Then lstMain is populated with the file names of the resources published to the URL.

Next   Step 3: Populate the Fields List Box