Below is code I am working with...
Everything works just fine except for the field names of the newly created linked table. Since there are no "headers" in the text file, the code just defaults every field name to "F1", "F2", "F3", "F4", etc..
I need to have the field names be something different...
How can I manipulate the code below to show a actual field name instead of "F1", "F2", "F3", "F4", etc..??
Any suggestions or examples..??
Thanks in advance..!!
jcw5107
Sub LinkAMPTxtFile()
On Error GoTo Err_LinkAMPTxtFile
Dim db As DAO.Database
Dim tbl As DAO.TableDef
Set db = CurrentDb
Dim filename
filename = "SCHEDMNT.TXT"
db.TableDefs.Delete "SCHEDMNT"
Set tbl = db.CreateTableDef("SCHEDMNT")
tbl.Connect = "Text;DATABASE=" & "D:/UPSData" & "; FMT=delimited;HDR=NO;IMEX=2"
tbl.SourceTableName = "SCHEDMNT.txt"
db.TableDefs.Append tbl
db.Close
Exit_LinkAMPTxtFile:
Exit Sub
Err_LinkAMPTxtFile:
If Err.Number = 53 Then
Resume Next
ElseIf Err.Number = 3265 Then
Resume Next
Else
DisplayMessage Err.Description
Resume Exit_LinkAMPTxtFile
End If
End Sub
Everything works just fine except for the field names of the newly created linked table. Since there are no "headers" in the text file, the code just defaults every field name to "F1", "F2", "F3", "F4", etc..
I need to have the field names be something different...
How can I manipulate the code below to show a actual field name instead of "F1", "F2", "F3", "F4", etc..??
Any suggestions or examples..??
Thanks in advance..!!
jcw5107
Sub LinkAMPTxtFile()
On Error GoTo Err_LinkAMPTxtFile
Dim db As DAO.Database
Dim tbl As DAO.TableDef
Set db = CurrentDb
Dim filename
filename = "SCHEDMNT.TXT"
db.TableDefs.Delete "SCHEDMNT"
Set tbl = db.CreateTableDef("SCHEDMNT")
tbl.Connect = "Text;DATABASE=" & "D:/UPSData" & "; FMT=delimited;HDR=NO;IMEX=2"
tbl.SourceTableName = "SCHEDMNT.txt"
db.TableDefs.Append tbl
db.Close
Exit_LinkAMPTxtFile:
Exit Sub
Err_LinkAMPTxtFile:
If Err.Number = 53 Then
Resume Next
ElseIf Err.Number = 3265 Then
Resume Next
Else
DisplayMessage Err.Description
Resume Exit_LinkAMPTxtFile
End If
End Sub