Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Exporting to XML (XP)

    I am using the following code to export to an XML file -
    Application.ExportXML acExportTable, "ErrorLog", strFileName, acAppendData
    it exports OK but does not append - it loses any previous records. Any idea why or how to get it to append?

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Exporting to XML (XP)

    After the filename, the ExportXML method expects the next parameter to be the SchemaTarget.
    acAppendData has the value 2, so you will have an additional file called 2 created.

    I can't see anything in Help for this method that allows for data to be appended.

    acAppendData is an option for importing XML into a table.
    Regards
    John



  3. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Exporting to XML (XP)

    it appears the answer is to open the file as an ADO recordset, append the record(s) and save it back.
    not easy to find the syntax to open it, spent ages trying to find the connection string, but as it is a text file you don't need one. just open it as a disconnected recordset
    Set rstErrorLog = New ADODB.Recordset
    rstErrorLog.CursorLocation = adUseClient ' as it is disconnected you must explicity set the cursor, as the default is server side but there is no server side for a disconnected record set.
    rstErrorLog.Open mstrXMLFilespec, "Provider=MSPersist", adOpenStatic, adLockBatchOptimistic, adCmdFile

  4. #4
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Exporting to XML (XP)

    If that works good.

    Does that cope with the fact that the xml file is not just a text file, so you can't just add the new records onto the end. They need to go after the existing records, but before the closing tag.
    Regards
    John



  5. #5
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Exporting to XML (XP)

    You manipulate the recordset as with any other, then kill the file (if it exists 'cause if it doesn't then kill will raise an error) then save the recordset back to the file
    rst.save strXMLFile, adPersistXML
    rst.close

    so you see the trick is that you cannot bind to an XML file, you load it into a disconnected recordset, do your work, kill the exiting file and create a new one. No Idea why you can't use a connection but you can't.

  6. #6
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Exporting to XML (XP)

    OK I understand that.
    Regards
    John



  7. #7
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Exporting to XML (XP)

    I misled you. you can work directly on the XML file. just replace
    adOpenStatic with adOpenDynamic
    I was fooled by the lack of a connection

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •