Getting data into a table using vba

davesmith202

Employee of Access World
Local time
Today, 16:12
Joined
Jul 20, 2001
Messages
522
I have some code that loops to parse some data. To get the data into a table, do I use Recordsets?

Is it easier to parse the data into a string, use split and then cycle that array to push the data into a table? Or perhaps do it on the fly when looping through my parsing code?

Code:
    Dim i As Integer

    'Cycle through lines
    For i = 0 To UBound(var) - 1
        'Check if Move line
        If (Len(var(i) > 0)) And (InStr(var(i), "[") = 0) Then
            'Cycle through Move lines only
            'Clear move line
            tmpMove = ""
            'Reset counter
           
            x = 0
            Do While (Len(var(i + x) > 0)) And (InStr(var(i + x), "[") = 0) And (UBound(var) > x + i - 1)
                'Add the current row marked by i+x
                
                tmpMove = tmpMove & var(i + x)
                x = x + 1
                If (UBound(var) < x + i) Then Exit Do
            Loop
            'Debug.Print i, x
            i = i + x
            'MsgBox tmpMove
            Debug.Print tmpMove
            'strPGNtoCSV = strPGNtoCSV & tmpMove & "," & Chr(10)
            strPGNtoCSV = strPGNtoCSV & tmpMove & ";" & Chr(10)
        Else
            Debug.Print var(i)
            'strPGNtoCSV = strPGNtoCSV & var(i) & "," & Chr(10)
            strPGNtoCSV = strPGNtoCSV & var(i) & ";" & Chr(10)
        End If
    
    Next
 
I have some code that loops to parse some data. To get the data into a table, do I use Recordsets?
I am not exactly sure what you are trying to do but I will pick up this thread on your first bit above.

You could use a recordset, make a new record, add the fields and then update in your parsing loop.

My thoughts are that you could simply use an SQL Update and execute it.
For the theory on an Update SQL see this for example http://www.w3schools.com/sql/sql_update.asp

Then you set an object to your DB before your loop

then in your loop you only need this

Code:
sql = "UPDATE SQL WITH PARSED STRINGS"
db.Execute sql
 

Users who are viewing this thread

Back
Top Bottom