J
Jeff
I am trying to import .dat files into an access database.
I have read article #306144 but cannot get the code to
work. What I am now trying to do is tie the code to a
forms button. Can someone help me accomplish importing
the following .dat file to the named table?
File: C:\Import Data\exceldr.dat
Access Table Name: Safety Points Earned_Drivers
Below is the code I am using, any help is greatly
appreciated:
Private Sub Data_Import_Click()
'Variables used to create and modify the file extension
Dim objFileSystem
Dim objFile
Dim strFileCopy As String
Dim intExtPosition As Integer
'Create an instance of the FileSystemObject to access
'the local file system
Set objFileSystem = CreateObject
("Scripting.FileSystemObject")
'Use the GetFile method to return a File object
corresponding to the
'file in a specified path.
Set objFile = objFileSystem.GetFile(strPath)
intExtPosition = InStr(objFile.Name, ".")
If intExtPosition > 0 Then
strFileCopy = Left(objFile.Name, intExtPosition -
1) & ".txt"
Else
strFileCopy = objFile.Name & ".txt"
End If
'Create a copy of the file with a .txt extension
objFile.Copy strFileCopy, True
DoCmd.TransferText acImportDelim, , strTableName,
strFileCopy, True
End Sub
I have read article #306144 but cannot get the code to
work. What I am now trying to do is tie the code to a
forms button. Can someone help me accomplish importing
the following .dat file to the named table?
File: C:\Import Data\exceldr.dat
Access Table Name: Safety Points Earned_Drivers
Below is the code I am using, any help is greatly
appreciated:
Private Sub Data_Import_Click()
'Variables used to create and modify the file extension
Dim objFileSystem
Dim objFile
Dim strFileCopy As String
Dim intExtPosition As Integer
'Create an instance of the FileSystemObject to access
'the local file system
Set objFileSystem = CreateObject
("Scripting.FileSystemObject")
'Use the GetFile method to return a File object
corresponding to the
'file in a specified path.
Set objFile = objFileSystem.GetFile(strPath)
intExtPosition = InStr(objFile.Name, ".")
If intExtPosition > 0 Then
strFileCopy = Left(objFile.Name, intExtPosition -
1) & ".txt"
Else
strFileCopy = objFile.Name & ".txt"
End If
'Create a copy of the file with a .txt extension
objFile.Copy strFileCopy, True
DoCmd.TransferText acImportDelim, , strTableName,
strFileCopy, True
End Sub