Code for 1 record = 1 xml file

  • Thread starter Thread starter eb
  • Start date Start date
E

eb

I want to export my access records from a query to 1 xml file per record. I
don't want to do each individually. Is there a standard vba code to do this?
The MS access help is not helping me.
 
eb said:
I want to export my access records from a query to 1 xml file per record.
I
don't want to do each individually. Is there a standard vba code to do
this?
The MS access help is not helping me.


There not really standard code, but you can roll your own. The code would
look somthing like:

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim qry As DAO.QueryDef
Dim strSql As String
Dim strwhere As String

Dim strOutPutDir As String
Dim strOutPutfile As String

Set db = CurrentDb
On Error Resume Next
Set qry = db.CreateQueryDef("q1", "")
If Err.Number <> 0 Then
Set qry = db.QueryDefs("q1")
End If
On Error GoTo 0

strOutPutDir = "c:\xtest\"

strSql = "select * from MyQueryToExport"
Set rst = CurrentDb.OpenRecordset(strSql)
Do While rst.EOF = False
strSql = "select * from MyQueryToExport where id = " & rst!ID
qry.SQL = strSql
strOutPutfile = strOutPutDir & "t" & rst!ID & ".xml"
ExportXML acExportQuery, "q1", strOutPutfile, , , , , acEmbedSchema,
strwhere
rst.MoveNext
Loop
rst.Close

End Sub
 
Back
Top