A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Load files from a directory into a database



 
 
Thread Tools Display Modes
  #1  
Old January 28th, 2006, 05:18 AM posted to microsoft.public.access.gettingstarted
external usenet poster
 
Posts: n/a
Default Load files from a directory into a database

Hello

I have been looking at samples and such and still cannot find an example for
this.

What I would like to do is loop through a directory and add files to a
recordset.

From what I understand this should be possible with a loop and an additem,
am I on the right track?

--
Peace,

Richard
  #2  
Old January 28th, 2006, 02:25 PM posted to microsoft.public.access.gettingstarted
external usenet poster
 
Posts: n/a
Default Load files from a directory into a database

Are you talking about a disconnected recordset, or do you actually want to
add the files to a table in your database?

For the latter, I'd do something like the following untested air-code (which
uses DAO, because that's what I always use with Jet databases):

Dim dbCurr As DAO.Database
Dim rsCurr As DAO.Recordset
Dim strFile As String
Dim strFolder As String

strFolder = "C:\MyData\" ' Note that the closing slash is important here

Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset("SELECT Folder, File FROM MyTable")

strFile = Dir(strFolder & "*.*")
Do While Len(strFile) 0
With rsCurr
.AddNew
!Folder = strFolder
!File = strFile
.Update
End With
strFile = Dir
Loop

rsCurr.Close
Set rsCurr = Nothing
Set dbCurr = Nothing

On the other hand, I'd probably just use an INSERT query, rather than a
recordset:

Dim strFile As String
Dim strFolder As String
Dim strSQL As String

strFolder = "C:\MyData\" ' Note that the closing slash is important here

strFile = Dir(strFolder & "*.*")
Do While Len(strFile) 0
strSQL = "INSERT INTO MyTable (Folder, File) " & _
"VALUES('" & strFolder & "', '" & strFile & "')
CurrentDb.Execute strSQL, dbFailOnError
strFile = Dir
Loop

I don't normally use disconnected recordsets, so it would take me a little
longer to cobble together an example, but hopefully the first sample above
gives you the general idea.


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Richard ROV" wrote in message
...
Hello

I have been looking at samples and such and still cannot find an example
for
this.

What I would like to do is loop through a directory and add files to a
recordset.

From what I understand this should be possible with a loop and an additem,
am I on the right track?

--
Peace,

Richard



  #3  
Old January 30th, 2006, 11:22 PM posted to microsoft.public.access.gettingstarted
external usenet poster
 
Posts: n/a
Default Load files from a directory into a database

Thanks for the response.

I found this example in the Knowledge Base

http://support.microsoft.com/default...b;en-us;198466

This example helped and if I comment out the [OLEFile].Class it runs.

--
Peace,

Richard


"Douglas J. Steele" wrote:

Are you talking about a disconnected recordset, or do you actually want to
add the files to a table in your database?

For the latter, I'd do something like the following untested air-code (which
uses DAO, because that's what I always use with Jet databases):

Dim dbCurr As DAO.Database
Dim rsCurr As DAO.Recordset
Dim strFile As String
Dim strFolder As String

strFolder = "C:\MyData\" ' Note that the closing slash is important here

Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset("SELECT Folder, File FROM MyTable")

strFile = Dir(strFolder & "*.*")
Do While Len(strFile) 0
With rsCurr
.AddNew
!Folder = strFolder
!File = strFile
.Update
End With
strFile = Dir
Loop

rsCurr.Close
Set rsCurr = Nothing
Set dbCurr = Nothing

On the other hand, I'd probably just use an INSERT query, rather than a
recordset:

Dim strFile As String
Dim strFolder As String
Dim strSQL As String

strFolder = "C:\MyData\" ' Note that the closing slash is important here

strFile = Dir(strFolder & "*.*")
Do While Len(strFile) 0
strSQL = "INSERT INTO MyTable (Folder, File) " & _
"VALUES('" & strFolder & "', '" & strFile & "')
CurrentDb.Execute strSQL, dbFailOnError
strFile = Dir
Loop

I don't normally use disconnected recordsets, so it would take me a little
longer to cobble together an example, but hopefully the first sample above
gives you the general idea.


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Richard ROV" wrote in message
...
Hello

I have been looking at samples and such and still cannot find an example
for
this.

What I would like to do is loop through a directory and add files to a
recordset.

From what I understand this should be possible with a loop and an additem,
am I on the right track?

--
Peace,

Richard




 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
help with storing image files in access database and displaying imagefiles in reports (access 2000) pheonix1t General Discussion 1 December 26th, 2005 02:59 AM
How can you burn the Windows Application Data Folder for email? shortstop643 Outlook Express 19 February 17th, 2005 12:25 PM
Encrypt AccesS File? milest General Discussion 2 February 9th, 2005 07:58 PM
Puzzler of the day... week??? EJF3 Powerpoint 17 October 22nd, 2004 06:46 AM
Product Key for Office XP P.G.Indiana Setup, Installing & Configuration 1 June 7th, 2004 03:22 AM


All times are GMT +1. The time now is 09:18 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.