Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file wont import help finding why

Status
Not open for further replies.

ch4meleon

Technical User
Jan 13, 2003
60
0
0
GB
I have some code very kindly given to me in thread 705-1142361 It has been working perfectly up to now but following some changes to the import files and therefore to the table that they import into now come up with an error message "Failed to Import File " (as you would expect)

code-

Function Searching4Excels(ByVal Search_Folder As String)

On Error GoTo BadImport
Dim ImportFileName As String

With Application.FileSearch
.NewSearch
.FileType = 4 'msoFileTypeExcelWorkbooks
'.Filename = File_Name & "*.xls"
.LookIn = Search_Folder
.SearchSubFolders = False
If .Execute > 0 Then
For iCount = 1 To .FoundFiles.Count
'LBound(.FoundFiles) To UBound(.FoundFiles)
ImportFileName = .FoundFiles(iCount)
ImportThisExcel ImportFileName
Next iCount
Else
MsgBox "No file found in " & Search_Folder, _
vbCritical + vbOKOnly, "Importing Excels"
End If
End With
Exit Function

BadImport:
Select Case Err.Number
' All the error numbers that may be raised
' by an import failure.
Case 2391 ', 222, 333, ...
MsgBox "Failed to Import File " & ImportFileName
Resume Next
Case Else
' Handle other Errors.
MsgBox Err.Description
End Select

End Function

Is there any way to find out why it wont import and what the problem is as i have checked the field types are the same, fields size etc and cant figure why they wont import

many thanks in hope
 
Comment out the On Error instruction to get more detailed error message(s).

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV I cant believe i didnt think of that but i didnt. It is now working and sorted fine
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top