' Collection of code snippets by Arne Vajhøj 
' (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
Option Explicit

' START CONFIGURATION
Dim connstr
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Database\MSAccess\Test.mdb;User Id=admin;Password=;"
' END CONFIGURATION

Sub DbImport(csvfnm,fromcol,tocol,countrycol,tblnam)
    Dim con,fso,tf,n,line,fields,sqlstr
    Set con = CreateObject("ADODB.Connection")
    con.Open connstr
    On Error Resume Next ' the line below will fail first time
    con.Execute "DROP TABLE " & tblnam
    con.Execute "CREATE TABLE " & tblnam & " (id INTEGER NOT NULL, ip1 NUMERIC(10,0), ip2 NUMERIC(10,0), country CHAR(2), PRIMARY KEY(id))"
    con.Execute "CREATE INDEX ixip1 ON " & tblnam & " (ip1)"
    con.Execute "CREATE INDEX ixip2 ON " & tblnam & " (ip2)"
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set tf = fso.OpenTextFile(csvfnm)
    n = 0
    Do While Not tf.AtEndOfStream
        line = tf.ReadLine
        n = n + 1
        fields = Split(line, ",")
        sqlstr = "INSERT INTO " & tblnam & " VALUES(" & n & "," & Replace(fields(fromcol-1),"""","") & "," & Replace(fields(tocol-1),"""","") & ",'" & Replace(fields(countrycol-1),"""","") & "')"
        con.Execute sqlstr
    Loop
    tf.Close
    Set con = Nothing
End Sub

Call DbImport("ip-to-country.csv",1,2,3,"whi")
Call DbImport("GeoIPCountryWhois.csv", 3, 4, 5, "mm")
MsgBox "Done"
