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
    'Not Found
  End If
Next ForLoopCounter

Good Luck

@ VB5, Big thanks man....

Your welcome rav, now if you don't mind, could you please mark this thread as solved. Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.