Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

VBA code running query error 3141

$
0
0
I am attempting to use the following code in the AfterUpdate event of an unbound control on a form. The form is to record payments of invoices. The user will enter the amount of a received cheque (in another textbox) and the invoice number being paid in [txtInvoiceNumber]. I hope to use the code to validate the invoice amount against the cheque amount. strSQL is copy/pasted from a query. If the form is open and txtInvoiceNumber populated, the query returns the correct amount of the invoice. The code, when run, returns run time error 3141 "the Select statement includes a reserved word, misspelling or punctuation"
Any help greatly appreciated
Access 2013 *.mdb file

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String

strSQL = "SELECT Sum([klaTotal]) AS InvoiceKLATotal" & _
"FROM (SELECT DISTINCTROW tblInvoices.OrderID," & _
"[UnitClientDisb]*[Quantity]+((([UnitKLAFees]+[UnitKLADisb]+[UnitTransfee])*[Quantity])*([gstRate]+1)) AS klaTotal" & _
"FROM tblInvoices INNER JOIN tblInvoiceDetails ON tblInvoices.OrderID = tblInvoiceDetails.OrderID" & _
"WHERE (((tblInvoices.OrderID)= [Forms]![frmPayments]![txtInvoiceNumber]))) AS InvoiceKLADetail;"

Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)

Set db = Nothing
Set rs = Nothing

Viewing all articles
Browse latest Browse all 13329

Trending Articles