Z
Zeta
Why do I get a compile error on the line
"ImportTextFile (.FoundFiles(i),TableName)"
In the first function? I am trying to pass the second
function two arguements. It works fine if I remove
the "TableName" arguement.
Thanks
Option Compare Database
Function FileSearch()
Dim strFilesFound As String
Dim strImportPath As String
Dim strtblName As String
Dim intResponse As Integer
Dim TableName As String
On Error GoTo Err_FileSearch
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
With rst
.CursorType = adOpenDynamic
.Open ("tblInfo"), CurrentProject.Connection 'This is
a table where I would store the default import path
'strImportPath = !ImportPath
'Use the function getPath to get the folder path with
data
strImportPath = getPath()
'User must enter the name of the table data will be
imported into
TableName = InputBox("What is the EXACT name of the
table that will accept the import", "LocateFiles ")
.Close
End With
Set rst = Nothing
With Application.FileSearch
.FileName = "*.rw1"
.LookIn = strImportPath
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
strFilesFound = strFilesFound & Chr$(10)
& .FoundFiles(i)
Next i
intResponse = MsgBox(.FoundFiles.Count & " File(s)
Found:" & Chr$(10) & strFilesFound _
& Chr$(10) & Chr$(10) & Format("Import and then
delete files?") _
, vbYesNo, "Confirmation")
If intResponse = vbYes Then
For i = 1 To .FoundFiles.Count
'If ImportTextFile(.FoundFiles(i)) = True Then
Kill (.FoundFiles(i)) 'removed to stop file delete
ImportTextFile (.FoundFiles(i),TableName)
Next i
MsgBox "Import completed"
End If
If intResponse = vbNo Then Exit Function
Else
MsgBox "No importable text files found in " &
strImportPath
End If
End With
Exit Function
Err_FileSearch:
Select Case Err
Case 3021
MsgBox "Import folder must be selected",
vbInformation
DoCmd.OpenForm "frmImportPath", acNormal 'lets
user select import path and save to tblInfo
Exit Function
Case Else
MsgBox Err & " " & Error$
End Select
End Function
Function ImportTextFile(strFileName As String, TableName
As String) As Boolean
On Error GoTo Err_ImportTextFile
DoCmd.TransferText acImportDelim, "CO", TableName,
strFileName, False
ImportTextFile = True
Exit Function
Err_ImportTextFile:
ImportTextFile = False
Select Case Err
Case 2391
MsgBox "An error occured while importing your
file" & strFileName & "." & vbCrLf & Format("File not
Imported nor Deleted", "bold"), vbCritical, "File Import
Error"
Case 2501
Exit Function
Case Else
MsgBox Err & " " & Err.Description
End Select
End Function
"ImportTextFile (.FoundFiles(i),TableName)"
In the first function? I am trying to pass the second
function two arguements. It works fine if I remove
the "TableName" arguement.
Thanks
Option Compare Database
Function FileSearch()
Dim strFilesFound As String
Dim strImportPath As String
Dim strtblName As String
Dim intResponse As Integer
Dim TableName As String
On Error GoTo Err_FileSearch
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
With rst
.CursorType = adOpenDynamic
.Open ("tblInfo"), CurrentProject.Connection 'This is
a table where I would store the default import path
'strImportPath = !ImportPath
'Use the function getPath to get the folder path with
data
strImportPath = getPath()
'User must enter the name of the table data will be
imported into
TableName = InputBox("What is the EXACT name of the
table that will accept the import", "LocateFiles ")
.Close
End With
Set rst = Nothing
With Application.FileSearch
.FileName = "*.rw1"
.LookIn = strImportPath
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
strFilesFound = strFilesFound & Chr$(10)
& .FoundFiles(i)
Next i
intResponse = MsgBox(.FoundFiles.Count & " File(s)
Found:" & Chr$(10) & strFilesFound _
& Chr$(10) & Chr$(10) & Format("Import and then
delete files?") _
, vbYesNo, "Confirmation")
If intResponse = vbYes Then
For i = 1 To .FoundFiles.Count
'If ImportTextFile(.FoundFiles(i)) = True Then
Kill (.FoundFiles(i)) 'removed to stop file delete
ImportTextFile (.FoundFiles(i),TableName)
Next i
MsgBox "Import completed"
End If
If intResponse = vbNo Then Exit Function
Else
MsgBox "No importable text files found in " &
strImportPath
End If
End With
Exit Function
Err_FileSearch:
Select Case Err
Case 3021
MsgBox "Import folder must be selected",
vbInformation
DoCmd.OpenForm "frmImportPath", acNormal 'lets
user select import path and save to tblInfo
Exit Function
Case Else
MsgBox Err & " " & Error$
End Select
End Function
Function ImportTextFile(strFileName As String, TableName
As String) As Boolean
On Error GoTo Err_ImportTextFile
DoCmd.TransferText acImportDelim, "CO", TableName,
strFileName, False
ImportTextFile = True
Exit Function
Err_ImportTextFile:
ImportTextFile = False
Select Case Err
Case 2391
MsgBox "An error occured while importing your
file" & strFileName & "." & vbCrLf & Format("File not
Imported nor Deleted", "bold"), vbCritical, "File Import
Error"
Case 2501
Exit Function
Case Else
MsgBox Err & " " & Err.Description
End Select
End Function