View Single Post
  #10 (permalink)  
Old July 29th, 2003, 06:49 AM
pgtips pgtips is offline
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Elmer, I don't know if you're interested in going down the text driver route, but it seems to me a simple solution to your problem.

As I said previously, I've never done this myself, but I've now had a chance to try it out and it worked just fine. Here's what I did:
1. created a text file called duplicates.txt in my C:\Temp directory and added duplicate entries for A,B,C as shown in your original post
2. created new VB project and added a reference to ADO
3. added a command button and list box to the form
4. added the following code to the Command1_Click, which uses the Text driver (I actually used the Jet version, but there is also ODBC version) to execute a DISTINCT SQL query against the text file and write the results into the list box.
Code:
Private Sub Command1_Click()

    Dim oConn As ADODB.Connection
    Dim oRs As ADODB.Recordset

    List1.Clear

    Set oConn = New ADODB.Connection

    oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
       "Data Source=c:\Temp\;" & _
       "Extended Properties=""text;HDR=No;FMT=Delimited"""

    Set oRs = New ADODB.Recordset

    oRs.Open "Select DISTINCT * From duplicates.txt", oConn, _
             adOpenForwardOnly, adLockReadOnly, adCmdText

    Do While Not oRs.EOF

        List1.AddItem oRs.Fields(0).Value
        oRs.MoveNext

    Loop

    oRs.Close
    oConn.Close

    Set oRs = Nothing
    Set oConn = Nothing

End Sub
After the code had run, the list box contained only one entry for each of A, B and C.

hth - I certainly learned a new trick today :)
Phil
Reply With Quote