|
-
Jan 3rd, 2011, 09:43 AM
#1
Thread Starter
Junior Member
Re: Check to see if multiple files exist
 Originally Posted by Doogle
If you're not interested in which file(s) may be missing then I'd modify your code
EDIT2:
If you wanted to report which files are missing (which, IMHO, is a better option) you could modify the code to this:
Code:
Private Sub Form_Load()
Dim strError As String
Dim CheckPath As Integer
Dim FileName(4) As String
FileName(0) = "file.bmp"
FileName(1) = "file2.bmp"
FileName(2) = "file3.bmp"
FileName(3) = "file4.bmp"
strPath = App.Path & "\files\"
Do
If UCase(Dir$(strPath & FileName(i))) = UCase(FileName(i)) Then
CheckPath = CheckPath + 1
Else
strError = strError & FileName(i) & vbCrLf
End If
i = i + 1
Loop Until i > 3
If CheckPath = 4 Then
frmMain.Show
Else
MsgBox "The Following File(s) are Missing From " & vbCrLf & _
strPath & vbCrLf & strError
End If
Unload Me
End Sub
Note that CheckPath is changed to an Integer variable and is the count of files found. If all 4 are found then frmMain is loaded, otherwise the MessageBox will display all those files not found (which are held in strError).
Thanks, that works great.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|