I have the above function. It works, almost, when the file it is searching for is found it does what it is supposed to do until it reaches the end of the directory list and then it comes back with this error: Run-Time error '5': Invalid procedure call or argument. If it does not find the file then everything works fine. It stops working on FileFinding = Dir.VB Code:
Public Function FileFinder(WatchDir As String) As String 'this function will find the file, if it does not find the file 'that means that it is correct, they have never sent us this file 'before Dim FileFinding As String Dim count As Integer Dim counts As String Dim result As Long Dim string2 As String Dim CaptionValue As Integer Dim Preferences As String Dim FileToDelete As String Dim DeleteMe As Boolean count = 0 FileFinding = Dir(WatchDir) 'Where to look for. Do Until FileFinding = "" count = count + 1 FileName = FileFinding If PreferencesDelimitor <> "" Then string2 = PreferencesDelimitor result = AmtInStr(FileName, string2) Preferences = PreferencesFileFormat - 1 If result <> Preferences Then CaptionValue = 2 StatusCaptionCase (CaptionValue) MoveFileTemp (FileName) End If Else MsgBox ("You MUST choose a Delimitor and File Format") Combo1.SetFocus End If FileFinding = Dir 'this is where error occurs If result = Preferences Then MoveFiles (FileName) FileToDelete = FileName DeleteMe = True End If If DeleteMe = True Then DeleteFileName (FileToDelete) DeleteMe = False End If Loop counts = CStr(count) FileFinder = counts End Function
Any suggestions??




Reply With Quote