?
Solved

Export individual records to xml

Posted on 2008-10-15
5
Medium Priority
?
546 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

719 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