以下は、データのクエリを実行し、結果をフラット ファイルにエクスポートするために使用するサンプルです。私はあなたが必要とするかもしれないものにそれをいくらか適応させました.
On Error GoTo Err_My_Click
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT * FROM MyTable", dbOpenDynaset)
If (rs.RecordCount <> 0) Then
rs.MoveFirst
Open "C:\Export\XML__MyFile.xml" For Output As #1
Do While rs.EOF = False
TempExportCount = TempExportCount + 1
Print #1, "<Item>"
Print #1, " <description>" & rs.Fields("[Description]").value & "</description>"
Print #1, "</Item>"
rs.MoveNext
Loop
End If
Exit_My_Click:
On Error Resume Next
rs.Close
Set rs = Nothing
Close 1#
Exit Sub
Err_My_Click:
If (Err.Number = 76) Then
MsgBox ("The program could not save the txt file." & vbNewLine & vbNewLine & _
"Make sure you have the following folder created: C:\Export\")
Else
MsgBox (Err.Description)
End If
Resume Exit_My_Click