Solved

Export individual records to xml

Posted on 2008-10-15
5
536 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
  • 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now