Option Compare Database ' in code module - must reference ADO
Option Explicit
Sub Main0()
Dim NewClient_tabledef As New TableDef
Dim NewClient_xml As Integer
Dim NewClient_recordset As New ADODB.Recordset
Dim NewClient_sql As String
Set NewClient_tabledef = CurrentDb.CreateTableDef("NewClient")
NewClient_tabledef.Fields.Append NewClient_tabledef.CreateField("name", dbText)
NewClient_tabledef.Fields.Append NewClient_tabledef.CreateField("phone", dbText)
On Error Resume Next
CurrentDb.TableDefs.Append NewClient_tabledef 'add the table to the DB
NewClient_recordset.Open "NewClient", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
NewClient_recordset.AddNew
NewClient_recordset.Fields("name").Value = "Susan"
NewClient_recordset.Fields("phone").Value = "123"
NewClient_recordset.Update
NewClient_recordset.AddNew
NewClient_recordset.Fields("name").Value = "Tina"
NewClient_recordset.Fields("phone").Value = "654"
NewClient_recordset.Update
NewClient_recordset.Close
Set NewClient_recordset = Nothing
NewClient_xml = FreeFile()
Open "NewClient.xml" For Output As NewClient_xml ' name of the external table
Print #NewClient_xml, "<table>"
NewClient_recordset.Open "NewClient_table", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Do While Not NewClient_recordset.EOF
Print #NewClient_xml, " <record>"
Print #NewClient_xml, " <name>" & NewClient_recordset.Fields("name") & "</name>"
Print #NewClient_xml, " <phone>" & NewClient_recordset.Fields("phone") & "</phone>"
Print #NewClient_xml, " </record>"
NewClient_recordset.MoveNext
Loop
Print #NewClient_xml, "</table>"
Close NewClient_xml
NewClient_recordset.Close
Set NewClient_recordset = Nothing
End Sub