Re: Strange Problem doing DOS Dir Command in VBA Help Please
- From: "Terry Kreft" <terry.kreft@xxxxxxxxx>
- Date: Thu, 25 Aug 2005 16:27:32 +0100
Shell is an asynchronous call. Follow Allens suggestion and use the Dir
function instead.
--
Terry Kreft
MVP Microsoft Access
"Bugs" <bugs007@xxxxxxxxxxxxxxx> wrote in message
news:430da914$0$19501$afc38c87@xxxxxxxxxxxxxxxxxxxxxxx
> Hi Everyone.
>
> This problem is driving me crazy.
>
> Im using Access2003.
>
> Basically what I wish to do is create a new record for each jpg bmp or gif
> file in the current directory.
>
> I need to just save the path and filename of each file in a table in its
own
> record
>
> I am trying to do a DOS command to do a DIR of jpg, bmp and gif files, and
> save the output to a file C:\Filelist.txt
> using the following line.
>
> Shell (Environ$("COMSPEC") & " /c Dir *.jpg *.bmp *.gif /S /B >
> C:\Filelist.txt")
>
> I then try to read that file into the Imagepath field with VBA doing the
> following:
>
> Dim Q as string
>
> Open "C:\Filelist.txt" For Input As #1
>
> While Not EOF(1)
>
> DoCmd.GoToRecord , , acNewRec
> Line Input #1, Q
> Imagepath = Q
>
>
> Wend
>
> Close#1
>
>
>
> Works OK first time used, creates a set of new records, one for each jpg
bmp
> and gif file in the directory. Bewdy.
>
> But on second and subsequent uses (and a change of the current directory)
it
> creates a duplicate of the previously created set of records instead of
the
> contents of C:\Filelist.txt (ie Pass1 creates records OK, Pass2 creates
same
> records as Pass1, Pass3 creates same records as pass2 etc)
>
> I checked C:\Filelist.txt and it has been created successfully each time
>
> Yet VBA reads its contents incorrectly. Seems to ignore the fact that
> C:\Filelist.txt has been overwritten.Always seems to
> be one pass behind.
>
> I have even tried using a macro to import C:\Filelist.txt as a table and
do
> an append query but same problem.
>
> The behaviour of C:\Filelist.txt is odd.
>
>
> Any help would be extremely appreciated.
>
>
> Thank you.
>
> Joe.
>
>
>
.
- Follow-Ups:
- References:
- Prev by Date: Re: Reference Error: Difference between UK office and US office?
- Next by Date: Need Help Checking Values in one table against two min max values in another
- Previous by thread: Re: Strange Problem doing DOS Dir Command in VBA Help Please
- Next by thread: Re: Strange Problem doing DOS Dir Command in VBA Help Please
- Index(es):
Relevant Pages
|