Importing .dat files

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
 
A

Adrian Jansen

What format is the .dat file ? Dat is a generic suffix used for all manner
of files. TransferText will only work on a text file, delimited or fixed
width in some manner.

--
Regards,

Adrian Jansen
J & K MicroSystems
Microcomputer solutions for industrial control
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top