Results 1 to 2 of 2
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    import txt into table (2000)

    Assume a text file of the following format:

    <tab>SSN<tab>FName<tab>LName<tab>BirthDate<CR><L F>
    i have an eror on this line:

    Dim db As Database

    wath library reference i must load..

    and this my macro:


    Public Sub ImportPeopleFile()
    Dim sRecBuff As String
    Dim aRecBuff() As String
    Dim aFiedVal() As String
    Dim idxRec As Long
    Dim hFile As Integer
    Dim db As Database
    Dim SQL As String
    DimFileName As String

    'Read file:
    hFile = FreeFile()
    Open FileName For Input As #hFile
    sRecBuff = Input(LOF(hFile),hFile)
    Close #hFile

    'Open Database:
    Set db = DBEngine.OpenDatabase("MyDatabase.mdb")

    'Process the we have read:
    aRecBuff = Split(sRecBuff, vbCrLf)
    For idxRecord = 0 To UBound(aRecBuff)
    aFieldVal = Split(aRecBuff(idxRecord))
    SQL = "INSERT INTO People(PeopleID,SSN,FName,LName,BirthDate)" & _
    " VALUES(" & CStr(idxRecord+1) & "," & _
    "'" & aFieldVal(1) & "'," & _
    "'" & aFieldVal(2) & "'," & _
    "'" & aFieldVal(3) & "'," & _
    "#" & aFieldVal(4) & "#)"
    db.Execute SQL
    Next idxRecord

    'Close Database:
    db.Close
    Set db = Nothing
    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: import txt into table (2000)

    You need a reference to the Microsoft DAO 3.6 Object Library.

Posting Permissions

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