Solved

Export individual records to xml

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access Crosstab Query with Multiple Values 4 32
How to use DLookup with IsNull Function 4 26
ms access filter query with empty combobox 5 29
Dcount help 2 16
This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
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…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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.

809 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