Question : csv delimeter problem when importing to adp

I hade some code from an earlier question, and now i 'm trying to use it in an other routine, i have a csv file with ; between the fields.
The first delimeter is found but then the code does not split the files anymore
veld 1 is filled but veld2 is the rest of the first line.

Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
Public Function Import_CSV_File()
 
Dim FileNum As Integer
Dim InputFile As String
Dim InputString As String
Dim veld1, veld2, veld3, veld4, veld5, veld6, veld7, veld8, veld9, veld10 As String

Dim i As Integer
Dim rst As New ADODB.Recordset
Dim strSQL As String
Dim DataVal() As String
strSQL = "Select * From tvd"
rst.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
                
FileNum = FreeFile()
InputFile = "C:\Temp\tvd.csv"        '<-- Change to your folder and path
Open InputFile For Input Access Read Shared As #FileNum

'Line Input #FileNum, InputString     '<--- To throw away the header line
Do Until EOF(FileNum) = True
     Input #FileNum, veld1, veld2, veld3, veld4, veld5, veld6, veld7, veld8, veld9, veld10         'Read the data in
    With rst
        .AddNew
        !veld1 = veld1
        !veld2 = veld2
        !veld3 = veld3
        !veld4 = veld4
        !veld5 = veld5
        !veld6 = veld6
        !veld7 = veld7
        !veld8 = veld8
        !veld9 = veld9
        !veld10 = veld10
       
        .Update
    End With
Loop

Close #FileNum

End Function

Answer : csv delimeter problem when importing to adp

Your code is a bit disarranged. You got the input twice and missed to correct the second. Here's the working version:

Public Function Import_CSV_File()

Dim FileNum As Integer
Dim InputFile As String
Dim InputString As String
Dim velds As Variant
Close #FileNum
Dim i As Integer
Dim rst As New ADODB.Recordset
Dim strSQL As String
Dim DataVal() As String
strSQL = "Select * From tvd"
rst.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
       
FileNum = FreeFile()
InputFile = "C:\Temp\tvd.csv"    '<-- Change to your folder and path
Open InputFile For Input Access Read Shared As #FileNum

'Line Input #FileNum, InputString   '<--- To throw away the header line
Dim NextLine As String
Do Until EOF(FileNum) = True
   Line Input #FileNum, NextLine     'Read the data in
  velds = Split(NextLine, ";")
  With rst
    .AddNew
    !veld1 = velds(0)
    !veld2 = velds(1)
    !veld3 = velds(2)
    !veld4 = velds(3)
    !veld5 = velds(4)
    !veld6 = velds(5)
    !veld7 = velds(6)
    !veld8 = velds(7)
    !veld9 = velds(8)
    !veld10 = velds(9)
    !veld11 = velds(10)
   
    .Update
  End With
Loop

Close #FileNum

End Function

Random Solutions  
 
programming4us programming4us