Re: Checking multiple locations for folder using IF statement



I am not seeing the problem, Ron. Have you figured it out yet? I do see one
error. In fact, I thought about it last night. This line
stpath = Replace(stpath, ":\", ":\BOOKS)
Should be
stpath = Replace(stpath, ":\", ":\BOOKS\")

I have reviewd the code and I don't see why it is getting that error. It
often happens if you have unbalanced If End If pairs. In the code I sent,
they are all equal and appear to be correct. I wonder if the problem could be
caused by the error above?

Let me know if you are still having problems with it.


"Ron" wrote:

Hi, could someone please look at Klatuu's code in this thread and tell
me why I'm getting a "Next Without For" error?

Thanks,

-Ron



Ron wrote:
This is very helpful Klatuu. I understand the logic now.

However, every time I run the code I get a "Next without For" error.
Not sure exactly where the problem lies, even after reading the help
section about it.

Thanks,

-Ron




Klatuu wrote:
You are opening it twice if it is on Drive L: because the second call to Dir
happend regardless of what your If statement does. Here is a rewrite of you
code that may help. It will loop through all drives from L: to Z: looking
for the path name with and without BOOKS.
Notice the use of th Chr function and the For Next. 76 is the Character
equivalent of L and 90 is Z. So, if you do a For Next starting at 76 and
ending at 90, convert the loop counter to a character, you have the next
drive letter.

Private Sub openpath_Click()
Dim stpath As String
Dim fixedpath As String
Dim intDrive as Integer
Dim blnFoundPath

fixedpath = Replace([Path], "/", "\")
fixedpath = Mid([fixedpath], 17)
For intDrive = 76 to 90
stpath = Chr(intDrive) & ":\" & fixedpath

If Dir(stpath, vbDirectory) <> "" Then
blnFoundPath = True
Else
stpath = Replace(stpath, ":\", ":\BOOKS)
If Dir(stpath, vbDirectory) <> "" Then
blnFoundPath = True
End If

if blnFoundPath then
Exit For
End If
Next intDrive

If blnFoundPath Then
Retval = Shell("explorer /e,/root, " & stpath, vbMaximizedFocus)
Else
MsgBox "Directory Does Not Exist or Is Not Mounted", vbOKOnly, _
"Warning..."
End If

End Sub



"Ron" wrote:


Hi all. The system that we have uses mounted directories. This means
that a client/matter number in the format of 12345/123 could be mounted
on any drive letter between L and Z. The other variable is that the
client/matter number could be mounted including the folder "BOOKS" or
not, ie 12345/123/BOOKS.

So, what I'm trying to do is open a folder, if it exists. First I want
to check whether the directory has been mounted on Drive L with the
whole 12345/123/BOOKS. If so, open the folder, if not, I check whether
only 12345/123 was mounted on drive L. If so, open the folder. I need
to do this for all the drive letters to see where the client/matter
directory is mounted.

There are already issues with my coding below as the folder will open
twice if the folder is mounted on Drive L. [PATH] is the value of the
full pathline as stored in a form's text box. I'm missing something
here and would appreciate any assistance.

Thanks,

-Ron



Private Sub openpath_Click()
Dim stpath As String
Dim fixedpath As String
Dim smallpath As String

fixedpath = Replace([Path], "/", "\")
smallpath = Mid([fixedpath], 17)
stpath = "L:\" & smallpath

If Not Dir(stpath, vbDirectory) = "" Then
Retval = Shell("explorer /e,/root, " & stpath, vbMaximizedFocus)
Else
smallpath = Mid([fixedpath], 11)
stpath = "L:\BOOKS" & smallpath
End If

If Not Dir(stpath, vbDirectory) = "" Then
Retval = Shell("explorer /e,/root, " & stpath, vbMaximizedFocus)
Else
MsgBox "Directory Does Not Exist or Is Not Mounted", vbOKOnly,
"Warning..."
End If

End Sub




.



Relevant Pages

  • Re: Checking multiple locations for folder using IF statement
    ... It will loop through all drives from L: to Z: looking ... Dim fixedpath As String ... Dim blnFoundPath ... So, what I'm trying to do is open a folder, if it exists. ...
    (microsoft.public.access.formscoding)
  • Re: Checking multiple locations for folder using IF statement
    ... It will loop through all drives from L: to Z: looking ... Dim fixedpath As String ... Dim blnFoundPath ... So, what I'm trying to do is open a folder, if it exists. ...
    (microsoft.public.access.formscoding)
  • Re: Checking multiple locations for folder using IF statement
    ... It will loop through all drives from L: to Z: looking ... Dim fixedpath As String ... Dim blnFoundPath ... So, what I'm trying to do is open a folder, if it exists. ...
    (microsoft.public.access.formscoding)
  • Re: How to password protect a bunch of Word document files at once?
    ... If you have plenty of space on the USB drive you may be OK. ... you would be well advised to create a folder on the ... > Do I assume this will work on USB Flash drives where all the documents ... >> Dim myFile, Password, PathToUse As String ...
    (microsoft.public.word.newusers)
  • Re: Using Sub RDB_Merge_Data()
    ... Sub RDB_Merge_Data ... Dim myCountOfFiles As Long ... MsgBox "No files that match the ExtStr in this folder" ... > I'm using Ron de Bruin's great bit of code to compile data. ...
    (microsoft.public.excel.programming)