Solved

Export individual records to xml

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access query with left expression 5 31
data analyst 3 50
Syntax error [Missing Operator] in query expression 7 33
Acc 2010 pause execution 10 10
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

861 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

25 Experts available now in Live!

Get 1:1 Help Now