Bigfoot,<br><br>Found this article in the VB6 Help which seems quite good.<br><br>I haven't used Data Classes myself - but the main advantage seems to be that you can create a data source - like a data control - that you can then bind controls like text boxes or list boxes to.<br><br><font color=blue><b><br>Creating a Data-Aware Class that Reads Records from a Delimited Text File</b><br><br><br>By creating a data-aware class, you can read data from a delimited text file into an ADO recordset and use the features of ADO to manipulate the data. You can then use the class as a data source in your application, binding controls on a form to fields in the recordset.<br><br>This topic shows how to create a data-aware class that reads data in a tab-delimited text file and provides methods for navigating through the data.<br><br>To create a data-aware class that reads data from a delimited text file <br><br>Create a class that acts as a data source.<br><br><br>Add code to read data from the text file into an ADO recordset.<br><br><br>Set the data source for the class. <br><br><br>Note This topic is part of a series that walks you through creating a simple database application that interacts with data in a tab-delimited text file. It begins with the topic <b>Interacting with Data in an ASCII Text File.</b><br><br>Create a Class that Acts as a Data Source<br>You can create a class that acts as a data source by inserting a class module in your project and specifying its data source behavior. First, insert a class module in your project by selecting Add Class Module from the Project menu. Then set the Name and DataSourceBehavior properties for the class.<br><br>For example, to create a CustomerDataSource class that can act as a data source, set the following properties:<br><br>Property Setting <br>Name CustomerDataSource <br>DataSourceBehavior vbDataSource <br><br><br>For More Information Data-aware classes are covered in depth in Creating Data-Aware Classes in the Programmer's Guide.<br><br>Add Code to Read Data from the Text File into an ADO Recordset<br>By reading data from a text file into an ADO recordset, you can use the features of ADO to manipulate the data. First, add a reference to the ADO object library by selecting References on the Project menu, then selecting Microsoft ActiveX Data Objects 2.0 Library in the References dialog box.<br><br>Then declare a Recordset object variable in the Declarations section for the class. For example, to declare a Recordset object variable for working with customer records from the Customers.txt file, add the following to the Declarations section:<br><br>Public rsCustomers As ADODB.Recordset<br><br>By declaring the variable as a public variable, you can use the built-in methods of the Recordset object in applications that use the data-aware class.<br><br>Finally, add code to the Class_Initialize event procedure for the class to read data from the text file. For example, add the following code to the Class_Initialize event procedure for the CustomerDataSource class to read data from the Customers.txt file into a recordset:<br><br>Private Sub Class_Initialize()<br><br> Dim fld As ADODB.Field<br> Dim strRow As String<br> Dim strField As String<br> Dim intPos As Integer<br><br> Set rsCustomers = New ADODB.Recordset<br><br> With rsCustomers<br> ' Set CustomerID as the primary key.<br> .Fields.Append "CustomerID", adChar, 5, adFldRowID<br> .Fields.Append "CompanyName", adChar, 40, adFldUpdatable<br> .Fields.Append "ContactName", adChar, 30, adFldUpdatable<br> .Fields.Append "ContactTitle", adChar, 30, adFldUpdatable<br> .Fields.Append "Address", adChar, 60, adFldUpdatable<br> .Fields.Append "City", adChar, 15, adFldUpdatable<br> .Fields.Append "Region", adChar, 15, adFldMayBeNull<br> .Fields.Append "PostalCode", adChar, 10, adFldMayBeNull<br> .Fields.Append "Country", adChar, 15, adFldUpdatable<br> .Fields.Append "Phone", adChar, 24, adFldUpdatable<br> .Fields.Append "Fax", adChar, 24, adFldMayBeNull<br> ' Use Keyset cursor type to allow updating records.<br> .CursorType = adOpenKeyset<br> .LockType = adLockOptimistic<br> .Open<br> End With<br><br> Open "Customers.txt" For Input As #1<br><br> Do Until EOF(1)<br> Line Input #1, strRow<br> With rsCustomers<br> .AddNew<br> For Each fld In .Fields<br> ' If a tab delimiter is found, field text is to the<br> ' left of the delimiter.<br> If InStr(strRow, Chr(9)) <> 0 Then<br> ' Move position to tab delimiter.<br> intPos = InStr(strRow, Chr(9))<br> ' Assign field text to strField variable.<br> strField = Left(strRow, intPos - 1)<br> Else<br> ' If a tab delimiter isn't found, field text is the<br> ' last field in the row.<br> strField = strRow<br> End If<br><br> ' Strip off quotation marks.<br> If Left(strField, 1) = Chr(34) Then<br> strField = Left(strField, Len(strField) - 1)<br> strField = Right(strField, Len(strField) - 1)<br> End If<br><br> fld.Value = strField<br><br> ' Strip off field value text from text row.<br> strRow = Right(strRow, Len(strRow) - intPos)<br> intPos = 0<br><br> Next<br> .Update<br> .MoveFirst<br> End With<br> Loop<br> Close<br><br>End Sub<br><br>Set the Data Source for the Class<br>When you specify a class as a data source by setting its DataSourceBehavior to vbDataSource, Visual Basic automatically adds a GetDataMember event to the class. The Class_GetDataMember event procedure is where you set the data source for the class by assigning it to the Data object for the class.<br><br>For example, to set the rsCustomers recordset as the data source for the CustomerDataSource class, add the following to the Class_GetDataMember event procedure:<br><br>Private Sub Class_GetDataMember(DataMember As String, Data As Object) Set Data = rsCustomersEnd Sub<br>For More Information For a discussion of data sources, see Creating a Data Source in the Programmer's Guide.<br><br>Step by Step<br>This topic is part of a series that walks you through using a data-aware class and ADO to create a simple database application that interacts with data in a tab-delimited text file.<br><br>To See <br>Go to the next step Creating a Form that Lets You View and Update Data from a Data-Aware Class <br>Start from the beginning Interacting with Data in an ASCII Text File <br></font> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href=
Cargill's Corporate Web Site</a><br>