Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 3rd, 2007, 01:48 AM
Authorized User
 
Join Date: Feb 2007
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do I export an access db table to xml?

I'm trying to accomplish this through a vb module in an access db and frankly have no idea where to start..I would like to export an xml file of a particular table...the db is access 2003...i guess I really need to know if there is a vb command for creating xml..any guidance appreciated.

 
Old April 3rd, 2007, 03:17 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

' This can be executed using VBA. You need to add Microsott Access 11.0 Library
Sub Export_AccessTable_2_XML()

Dim oAC As New Access.Application


oAC.OpenCurrentDatabase "C:\temp\Test.mdb"

oAC.ExportXML _
    ObjectType:=acExportTable, _
    DataSource:="Test", _
    DataTarget:="C:\temp\Test.xml", _
    SchemaTarget:="C:\temp\TestSchema.xml"

End Sub

Cheers
Shasur

http://www.vbadud.blogspot.com
 
Old April 3rd, 2007, 10:54 AM
Authorized User
 
Join Date: Feb 2007
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default

this is being run from a module..I get database is already open exclusively by another user...sorry Im a newb at vb....how can I set oAC.OpenCurrentDatabase to the current db w/o a relative path?

 
Old April 3rd, 2007, 05:44 PM
Authorized User
 
Join Date: Feb 2007
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok...following is how I've worked through this...what i don't understand is why I cant print the recordset results without including the GetValue command...is there a better way to print the results of my recordset?
Code:
Public Sub WebExtract()
Dim ds As DAO.Recordset
Dim SQL As String
Dim fso
Dim act
Dim file_being_created
Dim oAC As New Access.Application
Set fso = CreateObject("scripting.filesystemobject")
SQL = "SELECT * FROM Inventory WHERE DisplayOnWeb=true;"
Set ds = CurrentDb.OpenRecordset(SQL)
' Writes the db output to a .xml file in the same directory
Set act = fso.CreateTextFile("c:\web_items.xml", True)
' All non repetitive xml on top goes here
act.WriteLine ("<?xml version=""1.0"" encoding=""ISO-8859-1""?>")
act.WriteLine ("<?xml-stylesheet type=""text/xsl"" href=""web_items.xsl""?>")
act.WriteLine ("<web_inventory>")
' Meat and potatoes
While Not ds.EOF
act.WriteLine ("<item id=" + "'" + GetValue(ds![Item Number]) + "'" + ">")
act.WriteLine ("<description>" + GetValue(ds!Description) + "</description>")
act.WriteLine ("<Cost>" + GetValue(ds!Cost) + "</Cost>")
act.WriteLine ("</item>")
ds.MoveNext
DoEvents
Wend
ds.Close
'close tags
act.WriteLine ("</web_inventory>")
End Sub
 
Old April 3rd, 2007, 11:56 PM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 221
Thanks: 0
Thanked 0 Times in 0 Posts
Default

one line will do a lot of work...
rst.open (<open up the sql statement as you need the data>)

-> here-> rst.Save App.Path & "\data1.xml", adPersistXML (this one line)
Its called FRO,check it out for more useful help.

Hope this helps.

With Regards,
Raghavendra Mudugal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Export Mircosoft Excel Data to Access Table tiyyob Excel VBA 0 January 11th, 2006 06:19 AM
How to Export SQL Server Table to XML file??? bekim XML 1 October 4th, 2004 03:52 AM
Export Table from Access to Excel aramchan Access VBA 2 July 12th, 2004 03:20 PM
Export table to txt in Access XP midtowncreek Access 9 May 24th, 2004 08:02 AM
Export to XML from DB HamishF SQL Server 2000 8 December 21st, 2003 05:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.