Chapter 16: Working with External Data
605
MsgBox “The File “ & sFileName & _
“could not be found”
MsgBox “Copy the file to “ & CurDir() _
& “ to continue”
Exit Function
End If
‘ Create Tabledef:
Set db = CurrentDb
Set td = db.CreateTableDef(sTableName)
sType = “Text;”
sDSN = “DSN=“ & sDSN & “;”
sFMT = “FMT=“ & sFMT & “;”
sHDR = “HDR=“ & sHDR & “;”
sIMEX = “IMEX=“ & sIMEX & “;”
sDatabase = “DATABASE=“ & sPath
sConnect = sType & sDSN & sFMT & sHDR & sIMEX & sDatabase
td.Connect = sConnect
td.SourceTableName = sFileName
db.TableDefs.Append td
LinkText = True
ExitHere:
Exit Function
HandleError:
Select Case Err
Case conTableExists
sMsg = “The table “ & sTableName _
& “ already exists.”
Case Else
sMsg = “Error#” & Err & “: “ & Error$
End Select
MsgBox sMsg, vbExclamation + vbOKOnly, _
“Error in Procedure “ & sFunction
LinkText = False
Resume ExitHere
End FunctionAssuming you’ve created an import link specification named EmployeeImport Link
Specification, the following statement uses the LinkText() function to link data from the
Empimp.txt file to a new table named EmployeeLink.On the CD-ROM
The sample database, Chapter16.accdb, already contains this import link specification and the
LinkText() function. The text file ImpFixed.txt, which contains fixed-length data, is also found on the
companion CD.
Use a statement like the following to link ImpFixed.txt to a table named EmployeeLink:LinkText(“ImpFixed.txt”, _
“EmployeeImport Link Specification”, _
“Fixed”, “NO”, “2”, “EmployeeLink”)