Re: multiple xml imports from local path



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" <Martijn@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C14B6BA3-E5F4-4051-87FE-A1AAE9D18DF1@xxxxxxxxxxxxxxxx
> 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"
>> <Martijn@xxxxxxxxxxxxxxxxxxxxxxxxx> 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.
>>
>>


.



Relevant Pages

  • Re: Checking a folder again after it has been emptied
    ... that while loop. ... allowing additional files in that folder to be moved and now with your ... #sleep timer and number of files ... closedir PRV_SRC_1; ...
    (perl.beginners)
  • Re: Outlook 2003 vba macro
    ... Don't move or delete items in a For Each loop! ... 'Move the email Item to the backup folder ... Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers ... > Dim objApp As Application ...
    (microsoft.public.outlook.program_vba)
  • Re: Help with a long running process?
    ... Before the loop enters its initial cicle, it will first have to grab ... all the files from all sub folders off the base path you specified. ... String)) or return it as an array. ... consider loading the files folder by folder: ...
    (microsoft.public.dotnet.languages.vb)
  • Re: problems deleting email messages in c#
    ... Deleting items from a collection requires either a count down for loop or another looping construct that tests for the collection being empty. ... Hard-deleting an item (bypassing Deleted Items) is only possible using CDO 1.21 or Extended MAPI or a COM wrapper for MAPI such as Redemption. ... An alternative is to handle ItemAdd on the Items collection of the Deleted Items folder. ... I am putting together a personal project to help me remove spam out of my ...
    (microsoft.public.office.developer.outlook.vba)
  • Re: multiple xml imports from local path
    ... > Dirto loop through all the files in a folder. ... > Private Sub btnImportAllFiles_Click ... > Dim strfile As String ...
    (microsoft.public.access.externaldata)