Image of Navigational Map linked to Home / Contents / Search Text ISAM from Microsoft

Tom Brennfleck - GUI Computing
Image of Line Break

I have been doing some text imports to an access file recently and thought "Why not use the new text ISAM from Microsoft?". I did not think that the routine would be as easy as that described below. With three to four lines of code you can import a text file into any database.

The code below was originally developed as VB4-16 Bit code, but I have tested the code under VB3 and it showed no problems. The only requirement was to add the text ISAM to the 'installable' ISAM's section of the ini file. Other than that, it worked like a charm.

  Function ImportTextFile(sSourceFile As String, sDestinationFile As String) As Integer
  Dim dDestination As Database
  Dim dSource As Database
  Dim dsSource As Dynaset
  Dim sConnect As String
  Dim sOldTblName$, sNewTblName$

  On Error GoTo ImportTextFileErr

    ' Open destination database
    Set dDestination = OpenDatabase(sDestinationFile)
    ' Mmake table names
    sOldTblName = MakeTableName(sSourceFile, False, dDestination)
    sNewTblName = MakeTableName(sSourceFile, True, dDestination)
      ' Make the connect string
    sConnect = "[Text;database=" & StripFileName(sSourceFile) & "]."

      ' Make the sql statment
    sSQL = "select * _
        into " & sNewTblName & " _
        from " & sConnect & sOldTblName
      ' Execute the sql statment
      dDestination.Execute sSQL

    ImportTextFile = True
    Exit Function
    ImportTextFile = False
  End Function

Download the example file, (11Kb), to get the full source code and test rig. The example files include a text file for you to import. I suggest you use the included text file and bibli.mdb as the destination database file for a first try.

Written by: Tom Brennfleck
August '96

Image of Arrow linked to Previous Article Image of Arrow linked to Next Article
Image of Line Break