Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   Index   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon  
 
Tips & Tricks

New Tips Added Weekly!
Click here to get on our Mailing List

   
 
MS Access

List Files in a Folder

How to get a List of all files in a Folder

You have a folder full of images that you want to add to a database.

Create a Table called tblPictures with the following schema:

FieldNameDataType
PictureIDAutonumber
PicturePathText
PictureNameText
PictureSizeInteger

Now you can create a Module in Access and add the following code.

Just call the Function passing in your folder.

ListFiles("D:\Folder\")

	Option Compare Database
	' Add Ref to Microsoft Scripting Runtime
	Sub ListFiles(mySourcePath)
		 
		Dim Counter As Integer
		 
		Set myObject = New Scripting.FileSystemObject
		Set mySource = myObject.GetFolder(mySourcePath)
		 
		On Error Resume Next
		 
		Dim db As Database
		Dim rs As Recordset
		Dim mysql As String
		 
		Set db = CurrentDb
		mysql = "tblPictures"
		Set rs = db.OpenRecordset(mysql, dbOpenDynaset)
		 
		For Each myFile In mySource.Files
			rs.AddNew
			rs![PicturePath] = myFile.Path
			rs![PictureName] = myFile.Name
			rs![PictureSize] = myFile.Size
			rs.Update
			 
			Counter = Counter + 1
		Next
		 
		' Clean up
		rs.Close
		db.Close
		Set rs = Nothing
		Set db = Nothing
		
		Set myObject = Nothing
		Set mySource = Nothing
		
		MsgBox "Listed " & Counter & " Files."
		 
	End Sub
	
tblPictures
PictureIDPicturePathPictureNamePictureSize
55D:\...\Blank.pngBlank.png1794
56D:\...\Datasheet.pngDatasheet.png1862

Download Source

Source

 

Alex Hedley (Avatar) By: Alex Hedley


Click here to sign up for more FREE tips

 

 

 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2024 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 3/28/2024 9:21:17 AM. PLT: 0s