Visual Basic Concepts

Creating the MyDataSource Class

See Also

In the previous topic, we created a class that implements an OLE DB Simple Provider. In this step we'll create another class that will provide data from the MyOSPObject class to other objects.

Note   This topic is part of a series that walks you through creating sample data source components. It begins with the topic Creating Data Sources.

To create the MyDataSource class

  1. Select the MyDataComponent project in the Project Explorer.

  2. Select Add Class Module from the Project menu, then choose Class Module from the Add Class Module dialog box.

  3. Select the Properties window and set the following properties for the new class module:
    Property Setting
    (Name) MyDataSource
    DataSourceBehavior 1-vbDataSource

  4. In the Object box, select Class. In the Procedure box, select the GetDataMember event. Add the following code to the Class_GetDataMember event procedure:
    Private Sub Class_GetDataMember(DataMember As String, Data As Object)
       ' Declare an instance of the MyOSPObject class
       Dim MyOSP As New MyOSPObject
    
       ' Make sure the DataMember is valid
       If DataMember = "" Then
           Err.Raise (E_FAIL)
       End If
    
       ' Set the FilePath property
       MyOSP.FilePath = DataMember
    
       ' Call the LoadData method to populate the class
       MyOSP.LoadData
    
       ' Set MyDataSource's data to MyOSPObject's data
       Set Data = MyOSP
    End Sub
    
  5. Choose Save Project Group from the File menu to save your changes. When prompted for a file name for the Class module, choose the default (MyDataSource.cls).

As you may have noticed, this class is much simpler than the MyOSPObject class. In fact, if you go back and compare it with the GetDataMember event, you'll see that it's doing essentially the same thing. The main difference here is that we're using a class that we created rather than the pre-existing ADODB class.

In the next step, we'll convert the form that we created earlier to use our new data source object, and we'll test it to see the results.

Step by Step

This topic is part of a series that walks you through creating sample ActiveX data sources.

To See
Go to the next step Testing the MyData Component
Start from the beginning Creating Data Sources