Export table to XML programmatically

  • Thread starter Thread starter gan
  • Start date Start date
G

gan

Hi, I'd like to know how to write a program which similar to the new feature
in Access XP, where user is allowed to export table (or query) to XML file.

Thanks in advance!!
 
something like this?

Public Function ExportRSToXML( _
ByVal strSql As String, _
ByVal strFileName As String) _
As Boolean
On Error GoTo ExportRSToXML_Error

Dim rs As ADODB.Recordset
Dim objStream As ADODB.Stream

Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open strSql, CurrentProject.Connection, adOpenKeyset,
adLockOptimistic

Set objStream = New ADODB.Stream
objStream.Type = adTypeText

rs.Save objStream, adPersistXML
objStream.SaveToFile strFileName, adSaveCreateNotExist

ExportRSToXML = True

ExportRSToXML_Exit:
rs.Close
Set rs = Nothing

objStream.Close
Set objStream = Nothing

Exit Function

ExportRSToXML_Error:
Resume ExportRSToXML_Exit

End Function
 
Back
Top