Text ISAM from Microsoft
Tom Brennfleck - GUI Computing
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
dDestination.Close
ImportTextFile = True
Exit Function
ImportTextFileErr:
ImportTextFile = False
dDestination.Close
End Function
Download the example file, import.zip (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.