By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,841 Members | 1,736 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,841 IT Pros & Developers. It's quick & easy.

Does [Sub]Directory Exist?

100+
P: 675
I want to manage images to use on my form, multiple images per record (row in primary table). I will

put these images in a folder, not as part of a table. There may be 12,000 rows in the table, and 20+

images/row.

I have no problem displaying the pictures. imgDisplayPhoto.Picture = Path & strPicName & ".jpg"

works very well if I hardcode Path. i.e. Form_Load has the statement: Path = "C:\MyProgram\Images\"

I can trap any errors, and display my default picture ("No Image Exists") if none exists.

My users might have the pictures in one-of-three places. 1-With the program; 2-Sub-Directory of the

Program Directory (Preferred); 3-Somewhere else. The user states where the pictures are. This is

straightforward and simple, and not my question.

After the user states where the pictures are located, I want to verify that the path is valid. Also, on

subsequent uses of the program, I need to know if the [Sub-]Directory still exists. It seems that

FolderExists and/or FileExists and/or DriveExists Method would solve my problem.

Access Help has "object.FileExists(filespec)" where "object is Required. Always the name of a

FileSystemObject". What is a FileSystemObject? Access Help is not crystal clear (no surprise), and

http://msdn2.microsoft.com/en-us/library/d6dw7aeh.aspx doesn't help.

I need a statement, function, or method that gives the answer to the question "Does the Folder " &

FolderName & " Exist?", and if the answer is to use FolderExists, how do I use it (give an example)?
Dec 5 '07 #1
Share this Question
Share on Google+
5 Replies


ADezii
Expert 5K+
P: 8,669
I want to manage images to use on my form, multiple images per record (row in primary table). I will

put these images in a folder, not as part of a table. There may be 12,000 rows in the table, and 20+

images/row.

I have no problem displaying the pictures. imgDisplayPhoto.Picture = Path & strPicName & ".jpg"

works very well if I hardcode Path. i.e. Form_Load has the statement: Path = "C:\MyProgram\Images\"

I can trap any errors, and display my default picture ("No Image Exists") if none exists.

My users might have the pictures in one-of-three places. 1-With the program; 2-Sub-Directory of the

Program Directory (Preferred); 3-Somewhere else. The user states where the pictures are. This is

straightforward and simple, and not my question.

After the user states where the pictures are located, I want to verify that the path is valid. Also, on

subsequent uses of the program, I need to know if the [Sub-]Directory still exists. It seems that

FolderExists and/or FileExists and/or DriveExists Method would solve my problem.

Access Help has "object.FileExists(filespec)" where "object is Required. Always the name of a

FileSystemObject". What is a FileSystemObject? Access Help is not crystal clear (no surprise), and

http://msdn2.microsoft.com/en-us/library/d6dw7aeh.aspx doesn't help.

I need a statement, function, or method that gives the answer to the question "Does the Folder " &

FolderName & " Exist?", and if the answer is to use FolderExists, how do I use it (give an example)?
One way to find out if a Folder exists is the following:
  1. Create a Reference to the Microsoft Scripting Runtime.
  2. Copy and Paste this Public Function to a Standard Code Module:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fDoesPathExist(strPathToFolder As String) As Boolean
    2. Dim fs
    3.  
    4. Set fs = CreateObject("Scripting.FileSystemObject")
    5.  
    6. fDoesPathExist = fs.FolderExists(strPathToFolder)
    7. End Function
  3. Check for the existence of a Folder with similar code to that posted below:
    Expand|Select|Wrap|Line Numbers
    1. 'Pass the Folder's Path (fully qualified) to the Function
    2. If fDoesPathExist("C:\Folder_1\Folder_2\Folder_3") Then
    3.   Debug.Print "Folder does exist"
    4. Else
    5.   Debug.Print "Folder does not exist"
    6. End If
  4. You could also use the Dir$() Function in similar fashion:
    Expand|Select|Wrap|Line Numbers
    1. If Dir$("C:\Windows\System32", vbDirectory) <> "" Then
    2.   Debug.Print "Folder exists"
    3. Else
    4.   Debug.Print "Folder does not exist"
    5. End If
Dec 5 '07 #2

100+
P: 675
Beautiful Answer! Thank you very much. I now have a standard function to test for the existance of a Folder or File from a string variable.

One logical place to store my images would be a SubFolder in the folder that contains the program. Is there any way to know the Path of the program from VB code?

Example: Program is C:\Access\ViewPics\ViewPics.mdb pictures would be at C:\Access\ViewPics\Images. I need a function that returns "C:\Access\ViewPics"
Dec 5 '07 #3

ADezii
Expert 5K+
P: 8,669
Beautiful Answer! Thank you very much. I now have a standard function to test for the existance of a Folder or File from a string variable.

One logical place to store my images would be a SubFolder in the folder that contains the program. Is there any way to know the Path of the program from VB code?

Example: Program is C:\Access\ViewPics\ViewPics.mdb pictures would be at C:\Access\ViewPics\Images. I need a function that returns "C:\Access\ViewPics"
  1. CurrentProject.Path will always return the Path to the Active Database as in:
    Expand|Select|Wrap|Line Numbers
    1. ? CurrentProject.Path ==> C:\Access\ViewPics
  2. 'To return the Path to the Images Directory:
    Expand|Select|Wrap|Line Numbers
    1. ? CurrentProject.Path & "\Images\" ==> C:\Access\ViewPics\Images\
Dec 5 '07 #4

100+
P: 675
Again, THANK YOU !!!
I spent several hours in MSAccess Help, www.Microsoft. . . , Google, and theScripts Search trying to find this.
Thank you very much again.

OldBirdman
Dec 5 '07 #5

ADezii
Expert 5K+
P: 8,669
Again, THANK YOU !!!
I spent several hours in MSAccess Help, www.Microsoft. . . , Google, and theScripts Search trying to find this.
Thank you very much again.

OldBirdman
You are always welcome.
Dec 6 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.