Solved

Export individual records to xml

Posted on 2008-10-15
5
542 Views
Last Modified: 2012-06-27
I have a table in Acccess with multiple records. How can I export each record in the table to an xml file? I think what I want is some vba code to loop through the table and export each record to its own xml file. I have no idea where to find something like that. Any help would be appreciated.
0
Comment
Question by:dodgerfan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:tchamtieh
ID: 22724388
I assume you already know how to connect to Access and retrieve a DataSet (see http://msdn.microsoft.com/library/en-us/vbcon/html/vbtskcreatingconnectiontoaccessdatabase.asp and http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemdataoledboledbdataadapterclasstopic.asp product documentation articles).

From that point on, you can use the dataset's XML capabilities, such as GetXML() or WriteXML() methods to get an XML representation of the data (again, look at the product documentation, there're a number of examples on how to do it. Then, you use an XSLT stylesheet (there're a number of tutorials on XSLT, such as www.w3schools.com/xsl/default.asp, and the W3C spec itself at www.w3.org/TR/xslt) to transform it into the HTML output you want.
0
 

Author Comment

by:dodgerfan
ID: 22725387
I'm using just Access 2007. I want to export each record to its own xml file. So if I have 10 records, I need to create 10 xml files. I can export the entire table easily to xml. But I need to do it on a record by record basis. So the code would need to loop through each record, export it to an xml file and give it a name based on something unique in the record, maybe the id field.
0
 
LVL 26

Accepted Solution

by:
dannywareham earned 500 total points
ID: 22736281
Are they all in the same table? I'm assuming they are.
Here's the bones for you. Let me know if you need more help...


Dim mySQL as String
Dim myRST as ADODB.Recordset
Dim myXML as String
 
mySQL = "SELECT xmlstring FROM yourtable"
        Set myRST = New ADODB.Recordset
        myRST.Open mySQL, CurrentProject.Connection
            Do While Not myRST.EOF
              'get xml field from your table/query
               myXML = fields("xmlstring") 
 
              'here you need to decide what you're doing with it
              'DoCmd.OutputTo is an option with a bit of work
 
           myRST.MoveNext
           Loop
           myRST.Close
           Set myRST = Nothing

Open in new window

0
 

Author Closing Comment

by:dodgerfan
ID: 31506428
Excellent! Thanks for the help. My final code looks different, but I uesed yours as a jumping off point. It works great. Thanks!
0
 
LVL 26

Expert Comment

by:dannywareham
ID: 22744358
Glad you're sorted.
Let me know if you need anything else
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question