checking for drive
Thanks Dave this was exactly what I needed.
"Dave Peterson" wrote:
I think you have all you need.
Option Explicit
Function DoesPathExist(myPath As String) As Boolean
Dim TestStr As String
If Right(myPath, 1) < "\" Then
myPath = myPath & "\"
End If
TestStr = ""
On Error Resume Next
TestStr = Dir(myPath & "nul")
On Error GoTo 0
DoesPathExist = CBool(TestStr < "")
End Function
sub testme01()
dim myParentFolder as string
dim myFolder as string
myparentfolder = "U:\" 'something that I know exists
if doespathexist(myparentfolder) then
'keep going using U:
else
'switch to the C: drive
myparentfolder = "C:\"
end if
on error resume next
mkdir myparentfolder & "US 49"
mkdir myparentfolder & "US 49" & "\form 1257"
on error goto 0
myfolder = myparentfolder & "US 49" & "\form 1257"
'and use myfolder in the rest of your code.
end sub
========
untested, uncompiled--watch for typos.
jnf40 wrote:
Dave,
Iâll try this again as far as explaining everything I am wanting to do, I
think I may be confusing myself more than anything, but here goesâ¦
I want to check to see if drive âœU:â is valid, if so then I want to check
for directory âœUS 49â, if it is there fine if not create it. If directory âœUS
49â is there then I want to check for sub directory âœ1257 Formsâ, if it is
there then my file would save there, if it is not there then it would create
the sub directory âœ1257 Formsâ then save my file there.
Now if drive âœU:â is not a valid drive then it would check, create, and save
everything as above in drive âœC:â So when all is finished I should have one
of the following paths:
âœU:\US 49\1257 Forms\my fileâ if âœU:â is a valid drive or
âœC:\US 49\1257 Forms\my fileâ if drive âœU:â is not a valid drive.
I have it now where it will do everything but check for and create the sub
directory. I hope I havenât muddied the waters more, I appreciate your
patience and knowledge.
--
Dave Peterson
|