Dim strSql As String, db As Database, sField As String
Dim qdf As QueryDef
Dim rs As DAO.Recordset
Set db = CurrentDb
strSql = "SELECT 'SI' AS Field1, trCustomer.trCustomerID, FORMS!frmExport!DefaultNominalCode AS Field3, '' AS Field4, trInvoiceHead.InvDate, trInvoiceHead.InvCode, 'Sales Invoice' AS Field7, trInvoiceHead.Total_Principal, FORMS!frmExport!DefaultTaxCode AS '' Field9, trInvoiceHead.Total_Tax, '' AS Field11, '' AS Field12 FROM trCustomer INNER JOIN trInvoiceHead ON trCustomer.trCustomerID=trInvoiceHead.trcustomerID WHERE InvRunKey=Forms!frmExport!InvRunCode;"
Set qdf = db.CreateQueryDef("qryExport", strSql)
DoCmd.TransferText acExportDelim, , "qryExport", "D:\export.csv", True
DoCmd.DeleteObject acQuery, "qryExport"
|