Daniel said:
Rick,
I keep getting an error "Sub or Fundtion Not defined" about the
'XMLEscape'
Sorry I forgot that I was using another custom function in there. In this
case it is a custom function to escape out special characters not allowed in
XML. Here is an example routine that writes the result to a file on the
root of your C drive. I have removed the custom function for the sake of
the example. This one uses attributes for fields instead of elements. I
have another that uses elements if you want that.
(with untested changes but pulled from a working app)
Function XMLAttributeOutputToFile(QryOrTblDef As String, Optional TableName
As Variant) As String
Dim MyDB As Database
Dim MyRS As Recordset
Dim fld As Field
Dim strText As String
Dim MyTableName As String
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset(QryOrTblDef, dbOpenSnapshot)
Open "C:\" & TableName & ".xml" For Output Shared As #1
Print #1, "<?xml version=""1.0""?>"
If IsMissing(TableName) = True Then
MyTableName = QryOrTblDef
Else
MyTableName = TableName
End If
Print #1, "<" & MyTableName & ">"
strText = strText & "<" & MyTableName & ">" & vbCrLf
With MyRS
Do Until .EOF
strText = " <Row"
For Each fld In MyRS.Fields
strText = strText & " " & fld.Name & "=" & Chr(34) &
MyRS(fld.Name) & Chr(34)
Next
Print #1, strText & "></Row>"
.MoveNext
Loop
End With
Print #1, "</" & MyTableName & ">"
Egress:
On Error Resume Next
Close #1
MyRS.Close
Set MyRS = Nothing
Set MyDB = Nothing
Exit Function
ErrHandler:
MsgBox Err.Description
Resume Egress
End Function