Hi Martijn,
Using Dir() in a loop like that is a long-established standard way of
processing multiple files in a folder in VBA, VB, and earlier versions of
Basic, and your code looks all right (although I have little experience with
Application.ImportXML).
In the VB editor, hit Ctrl-G to open the Immediate pane and then type:
ChDir "z:\XML_FILES"
? Dir("*.xml")
You should see the name of one of the XML files in the folder. Then type
? Dir()
This should produce the name of the next XML file.
If that is not happening, either you have typed the wrong folder name, or
there are no XML files in the folder - or perhaps the files are hidden.
"Martijn" <(E-Mail Removed)> wrote in message
news:C14B6BA3-E5F4-4051-87FE-(E-Mail Removed)...
> Hi John,
>
> Thanks for your replie!
> I did copy, paste and changed the code many times to get the result.
> Nothing worked, no error was given or files deleted / imported.
>
> The last change I made is written below, so maybe you (or another nice
> person can hekp me further out ;-))
>
> I made realy a lot of changes in the application.import code, like
> datasource:="strfile" etc, etc.
>
> What code will see the right file?, because it seems that there are no
> files
> to import.
> (Ofcourse I checked every way)
>
> The many files I got are named:
>
> client.xml
> client1.xml
> client2.xml
> etc.
>
> the last change I made:
> ***
>
> Private Sub btnImportAllFiles_Click()
>
> Dim strfile As String
>
> ChDir ("z:\XML_FILES")
> strfile = Dir("Client*.xml")
> Do While Len(strfile) > 0
>
> Application.ImportXML DataSource:="z:\XML_FILES\" & strfile,
> importoptions:=acAppendData
>
> Kill "Z:\XML_FILES\" & strfile
> strfile = Dir
> Loop
>
> End Sub
>
> ***
>
> It is a hard one!
>
> But thanks anyway!
>
> "John Nurick" wrote:
>
>> Hi Martijn,
>>
>> Another MVP, Joe Fallon, posted this code a while ago to show how to use
>> Dir() to loop through all the files in a folder. You'll need to replace
>> DoCmd.TransferText with Application.ImportXML and make a few other
>> changes.
>>
>> How to Import all Files in a Folder:
>>
>> Private Sub btnImportAllFiles_Click()
>> 'procedure to import all files in a directory and delete them.
>> 'assumes they are all the correct format for an ASCII delimited import.
>> Dim strfile As String
>>
>> ChDir ("c:\MyFiles")
>> strfile = Dir("FileName*.*")
>> Do While Len(strfile) > 0
>> DoCmd.TransferText acImportDelim, "ImportSpecName", "AccessTableName",
>> "c:\MyFiles\" & strfile, True
>> 'delete the file (consider moving it to an Archive folder instead.)
>> Kill "c:\MyFiles\" & strfile
>> strfile = Dir
>> Loop
>>
>> End Sub
>>
>> On Mon, 5 Sep 2005 04:51:09 -0700, "Martijn"
>> <(E-Mail Removed)> wrote:
>>
>> >I'm struggling with the import of xml files in access.
>> >
>> >I receive the files in outlook and save them as client(1).xml,
>> >client(2).xml
>> >etc in a local folder.
>> >When I'm using the xml import function in code I only can import a file
>> >I
>> >named in the code.
>> >
>> >example:
>> >Application.ImportXML DataSource:="D:\Clienten XML\client.xml",
>> >ImportOptions:=acAppendData
>> >(I can put in the same rule with client(2).xml etc, but there are a lot
>> >of
>> >files this way).
>> >
>> >This works fine but how can I tell the import engine that I want to
>> >import
>> >all the *.xml files from "this location" etc.
>> >
>> >I think I have to use a loop but I don't know how to define the code.
>> >
>> >Can somebody help me?
>> >
>> >Thanks
>>
>> --
>> John Nurick [Microsoft Access MVP]
>>
>> Please respond in the newgroup and not by email.
>>
>>
|