Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / July 2005

Tip: Looking for answers? Try searching our database.

Using the "Open" Command - Need fast

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark - 15 Jul 2005 19:24 GMT
Hello all and a big thanks for reading,

I am wanting to open a folder and prosess all the files in it. The first two
lines of code works, but it reads just 1 file at a time and I have to enter
in the name of the file.  Is there a way to have it open a folder then I can
pull the first file in and open it for input?  I tried this (last line #5) to
open a folder but get errors.

Open "C:\tote\T000645925837-DVD5-BATF.dat1" For Input As #1
Open "c:\tote\new\T000645925837-DVD5-BATF.dat1" For Output As #2

Open "C:\tote" For Input As #5
Mark - 15 Jul 2005 19:50 GMT
Think I miss word this.  Open will not work.  What command do I used to have
vb read a folders content?

> Hello all and a big thanks for reading,
>
[quoted text clipped - 8 lines]
>
> Open "C:\tote" For Input As #5
Dirk Goldgar - 15 Jul 2005 21:24 GMT
> Think I miss word this.  Open will not work.  What command do I used
> to have vb read a folders content?
[quoted text clipped - 11 lines]
>>
>> Open "C:\tote" For Input As #5

For what you want, the Dir() function is simpler and more efficient than
the FileSearch object.  Along these lines:

   Dim strFolder As String
   Dim strFile As String
   Dim intFileNo As Integer

   strFolder = "C:\tote\"

   strFile = Dir(strFolder & "*.*")

   Do Until Len(strFile) = 0

       ' Open and process file ...
       intFileNo = FreeFile()

       Open strFolder & strFile for Input As #intFileNo

       ' do something with the file ...

       Close intFileNo

       ' Get next file from folder, if any.
       strFile = Dir()

   Loop

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Brian - 15 Jul 2005 19:59 GMT
Here is an clip from the Access VBA help on the FileName property. It shows
how to loop through a folder, looking at a filtered list of the files (in
this example, cmd*) one at a time.

Set fs = Application.FileSearch
With fs
   .LookIn = "C:\My Documents"
   .FileName = "cmd*.*"
   If .Execute > 0 Then
       MsgBox "There were " & .FoundFiles.Count & _
           " file(s) found."
       For i = 1 To .FoundFiles.Count
           MsgBox .FoundFiles(i)
       Next i
   Else
       MsgBox "There were no files found."
   End If
End With

> Hello all and a big thanks for reading,
>
[quoted text clipped - 8 lines]
>
> Open "C:\tote" For Input As #5
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.