Dump all records of a table to a xml file
Dim MyConn, SQL_query,ResultSet,myName
'Open database connection
Set MyConn = CreateObject("ADODB.Connection")
MyConn.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\emp.mdb"
'Define the SQL query
SQL_query = "SELECT * FROM employee"
'Execute the query and store results in ResultSet
Set ResultSet = MyConn.Execute(SQL_query)
ResultSet.MoveFirst
Dim fso, tf
Set fso = CreateObject("Scripting.FileSystemObject")
Set tf = fso.CreateTextFile("c:\testfile.txt", True)
' Write a line with a newline character.
tf.WriteLine("<xml>")
While NOT ResultSet.EOF
tf.WriteLine("<employee>")
For each x in ResultSet.fields
tf.WriteLine(addXmlTag(x.name,x.value))
next
tf.WriteLine("</employee>")
ResultSet.MoveNext
WEND
tf.WriteLine("</xml>")
'Release resources
ResultSet.close
MyConn.close
Function addXmlTag(colName,colValue)
startTag ="<"
endTag=">"
addXmlTag = startTag & colName & endTag & colValue & startTag & "/" & colName & endTag
End Function
'Open database connection
Set MyConn = CreateObject("ADODB.Connection")
MyConn.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\emp.mdb"
'Define the SQL query
SQL_query = "SELECT * FROM employee"
'Execute the query and store results in ResultSet
Set ResultSet = MyConn.Execute(SQL_query)
ResultSet.MoveFirst
Dim fso, tf
Set fso = CreateObject("Scripting.FileSystemObject")
Set tf = fso.CreateTextFile("c:\testfile.txt", True)
' Write a line with a newline character.
tf.WriteLine("<xml>")
While NOT ResultSet.EOF
tf.WriteLine("<employee>")
For each x in ResultSet.fields
tf.WriteLine(addXmlTag(x.name,x.value))
next
tf.WriteLine("</employee>")
ResultSet.MoveNext
WEND
tf.WriteLine("</xml>")
'Release resources
ResultSet.close
MyConn.close
Function addXmlTag(colName,colValue)
startTag ="<"
endTag=">"
addXmlTag = startTag & colName & endTag & colValue & startTag & "/" & colName & endTag
End Function