Question : SQL syntax

Hi,

I have the following code in a VBA module.  I keep getting a syntax error message relating to the SQL SELECT statement.  Where have i gone wrong?

Reagrds,
Tom
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
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"

Answer : SQL syntax

let try this:
1:
2:
3:
4:
5:
Dim DefaultNominalCode As String = Forms!frmExport!DefaultNominalCode
        Dim DefaultTaxCode As String = Forms!frmExport!DefaultTaxCode
        Dim InvoiceRun As Integer = Forms!frmExport!InvoiceRun

        strSql = "select 'SI' AS [Field1], c.[trCustomerID], '" & DefaultNominalCode.Replace("'", "''") & "' AS [Field3], '' AS [Field4], i.[InvDate], i.[InvCode], 'Sales Invoice' AS [Field7], i.[Total_Principal], '" & DefaultTaxCode.Replace("'", "''") & "' AS [Field9], i.[Total_Tax],  '' AS [Field11],  '' AS [Field12] FROM trCustomer c INNER JOIN trInvoiceHead i ON c.trCustomerID = i.trcustomerID WHERE [InvRunKey] = " & InvoiceRun
Random Solutions  
 
programming4us programming4us