hi experts.

this is my first post here
hope you could help me..

Private Sub FindFile()
   
On Error GoTo x   'capture if error occurs
   
   Dim idx As Integer    'index to be incremented
   
   For idx = 1 To Combo.ListCount - 1   'loop to find the and load the text file
   
   
   RTB.LoadFile App.Path & "\Ordinance\" & Combo.List(idx) & "\" & txtFind.Text & ".txt"  'load the text
   
    Exit For  'if found

x:  Next idx   'if not found
 
End Sub

in my code, I have to catch the error which occurs when i want to load the File from an invalid directory,
I need to catch it to increment the index of my combo which contains the Exact name of sub folders where the Files are.

my problem is i can only catch the First error and increment the idx once(it can only change the Directory once)
then the error appears(The specified path/file name cannot be access )

why is that???
what's wrong with the Codes???


hope it's clear :icon_neutral:

Okay, if you want to see if a file or directory exists, you can use the Dir Function (see vb's help files for full description). So, what you would do, is something like...

Dim ForLoopCounter As Integer

For ForLoopCounter = 0 To Combo1.ListCount - 1
  If Dir(App.Path &  "\Ordinance\" & Combo.List(ForLoopCounter) & "\" & txtFind.Text & ".txt") <> vbNullString Then
    'Found
  Else
    'Not Found
  End If
Next ForLoopCounter

Good Luck

This question has already been answered. Start a new discussion instead.