R
RJF
I was having a problem with importing .dat files and Jeanette Cunningham
graciously helped me figure it out.
The code is working perfectly to automatically import the .dat file at the
push of a button. The only problem I'm having now is, when the file is
imported (as a text file) if there are errors, no messages appear to let the
user know that errors occurred during the import (like the message that
appears when you import manually).
Below is the code I'm using to import the file. I didn't DoCmd.SetWarnings
False and I've even tried putting DoCmd.SetWarning True at the beginning of
the code.
I'd appreciate any help.
Thanks,
Private Sub cmd_Import_Click()
On Error GoTo cmd_Import_Click_Err
Dim strFilter As String
Dim strInputFileName As String
Dim SourceFile, DestinationFile As String
Dim strSource As String
Dim strRenamed As String
strFilter = ahtAddFilterItem(strFilter, _
"All Files (*.*)", _
"*.*")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)
'remove the file extension from strInputFileName
strSource = Left$(strInputFileName, Len(strInputFileName) - 3)
strRenamed = strSource & "txt"
SourceFile = strInputFileName ' Define source file name.
DestinationFile = strRenamed ' Define target file name.
FileCopy SourceFile, DestinationFile ' Copy source to target.
DoCmd.TransferText acImportFixed, "ERSCUST_Import_Spec",
"ERSCUST", DestinationFile
Kill DestinationFile
MsgBox "Import Complete", , "Import"
cmd_Import_Click_Exit:
Exit Sub
cmd_Import_Click_Err:
MsgBox Error$
Resume cmd_Import_Click_Exit
End Sub
graciously helped me figure it out.
The code is working perfectly to automatically import the .dat file at the
push of a button. The only problem I'm having now is, when the file is
imported (as a text file) if there are errors, no messages appear to let the
user know that errors occurred during the import (like the message that
appears when you import manually).
Below is the code I'm using to import the file. I didn't DoCmd.SetWarnings
False and I've even tried putting DoCmd.SetWarning True at the beginning of
the code.
I'd appreciate any help.
Thanks,
Private Sub cmd_Import_Click()
On Error GoTo cmd_Import_Click_Err
Dim strFilter As String
Dim strInputFileName As String
Dim SourceFile, DestinationFile As String
Dim strSource As String
Dim strRenamed As String
strFilter = ahtAddFilterItem(strFilter, _
"All Files (*.*)", _
"*.*")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)
'remove the file extension from strInputFileName
strSource = Left$(strInputFileName, Len(strInputFileName) - 3)
strRenamed = strSource & "txt"
SourceFile = strInputFileName ' Define source file name.
DestinationFile = strRenamed ' Define target file name.
FileCopy SourceFile, DestinationFile ' Copy source to target.
DoCmd.TransferText acImportFixed, "ERSCUST_Import_Spec",
"ERSCUST", DestinationFile
Kill DestinationFile
MsgBox "Import Complete", , "Import"
cmd_Import_Click_Exit:
Exit Sub
cmd_Import_Click_Err:
MsgBox Error$
Resume cmd_Import_Click_Exit
End Sub