Rick Brandt posted the following the other day:
Here's a rude and crude DAO routine. Appropriate object
closing and error handling should be added, but it gives you
an idea.
Sub TableToXML()
Dim MyDB As Database
Dim MyRS As Recordset
Dim fld As Field
Dim RowTxt As String
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset("SELECT * FROM Table1")
Open "C:\Test.xml" For Output As #1
Print #1, "<?xml version=" & Chr(34) & "1.0" & Chr(34) &
"?>"
Print #1, " <Table1>"
Do Until MyRS.EOF = True
RowTxt = " <Row"
For Each fld In MyRS.Fields
RowTxt = RowTxt & " " & fld.Name & "=" & Chr(34) &
fld & Chr(34)
Next fld
Print #1, RowTxt & "></Row>"
MyRS.MoveNext
Loop
Print #1, " </Table1>"
Close #1
End Sub
Note that it has problems if the data contains special characters (accented
letters, etc.): a solution to that is to write a translator function that,
for example, converts é to é