Results 1 to 4 of 4

Thread: Get Datas from Text File separated with commas...

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2000
    Location
    LAVAL ( FRANCE )
    Posts
    32

    Unhappy

    Hi everyone !!

    I'd like to know how i could get datas from a Text file where datas are separated with commas. My aim is to get these datas and make them appear in different Textboxes as a Data Object can do... I need to do SQL request too with this text file... How could I do ??

    If someone could help...

    Thank you

    COSIDUS

  2. #2
    Fanatic Member Gary.Lowe's Avatar
    Join Date
    May 2000
    Location
    In my sphere of influence
    Posts
    621
    Cosidus

    Try this

    Code:
    Dim cnn As New ADODB.Connection
    Dim rstText As New ADODB.Recordset
        
    'Open the connection to the directory where the file is stored
    cnn.Open "Provider=MSDASQL;Driver={Microsoft text Driver (*.txt; *.csv)};DBQ=C:\Test"
        
    'Open the text file for import
    rstText.Open "test.txt", cnn, adOpenKeyset
    
    txtText1 = Trim(rstText.Fields(0))
    txtText2 = Trim(rstText.Fields(1))
    txtText3 = Trim(rstText.Fields(2))
    'ETC
    Hope this is of use to you




    Gary Lowe
    VB6 (Enterprise) SP5
    ADO 2.6
    SQL Server 7 SP3

    OK I know my spelling and grammer is crap so don't quote me on it!

    To err is human to take the P! is only natural !!

    Click on the top section of image for Marcus Miller website and bottom section of image for 'Run For Cover' sound clip


  3. #3
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    Or try this method, it doesn't use ODBC

    Code:
    'Uses ADO 2.1/5
    
        Dim cn As ADODB.Connection
        Dim rs As Recordset
        
        Set cn = New Connection
        Set rs = New Recordset
        
        'open connection to folder that contains the CSV file
        cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\;Extended Properties=Text;"
        
        'open the file
        rs.Open "select * from test.csv", cn
        
        'we have data
        MsgBox rs.Fields(1).Value

  4. #4
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    In the example that Gary.Lowe gave, how would you specify a different delimiter, such as ::

    It seems that your code only works if it's a comma..

    Any help would be appreciated..

    Dan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width