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

Examining the contents of a folder in Acess 2003

P: 8
Need to get a list of jpeg files in a folder in order to create a one to one set of records in a table.
Feb 20 '08 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 446
Hi
You will need to use the Dir() function recursively.
Expand|Select|Wrap|Line Numbers
  1.  Dim strNextFile As String 
  2. Dim strPath as String
  3.  
  4. 'set path to folder and to look for jpg files
  5. strPath = "C:\MyFolder\*.jpg" 
  6.  
  7. 'initialise Dir() function and get first filename
  8. strNextFile = Dir(strPath, vbNormal) 
  9.  
  10. 'turn off warnings
  11. Application.SetOption "Confirm Action Queries", False 
  12.  
  13. 'now loop using the Dir function until no more files found
  14. Do While strNextFile <> "" 
  15.  
  16. 'insert filename into table tblJPES
  17. DoCmd.RunSQL "INSERT INTO tblJPEGS (FilNam) Values (" & strNextFile & ");"
  18.  
  19. 'now call Dir recursively
  20. strNextFile = Dir
  21. Loop
  22.  
  23. 'turn warnings on
  24. Application.SetOption "Confirm Action Queries", False
  25.  
I have assumed the file names will be written to field FilNam in table tblJPEGS.

Hope this helps

S7
Feb 22 '08 #2

P: 8
Thanks Sierra7, was wondering if I would get a reply. Greatly Appreciated !
Feb 23 '08 #3

Expert 100+
P: 446
[
Your welcome.

There are other ways to save the retrieved data using Recordsets and the like but I think that looping through the files of the folder and reading the contents is the issue here.

Good luck with the rest of your program.

S7
Feb 24 '08 #4

Post your reply

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