Error SQL in VBA Access 2010 -



Error SQL in VBA Access 2010 -

i'm trying write query in ms access 2010 in order utilize print report, gives me "missing parameter" error in "set qd" line, hereunder code wrote, can please help me , tell me wrong code:

`private sub command5_click() dim qd dao.querydef dim rs dao.recordset dim strsql string dim strfrom, strto string strfrom = [forms]![frmprintselection]![txtfrom] strto = [forms]![frmprintselection]![txtto] strsql = "select tblinvoicehead.customernumber, tblcustomers.accountname,tblcustomers.address, tblcustomers.phone1, tblcustomers.phone2," _ & "tblcustomers.mobile1, tblcustomers.mobile2, tblinvoicehead.invoicenumber, tblinvoicehead.invoicedate, tblinvoicehead.totalinvoice," _ & "tblinvoicehead.cashdiscount, tblinvoicedetails.item, tblinvoicedetails.unit, tblinvoicedetails.qtn, tblinvoicedetails.price," _ & "tblinvoicedetails.[discount%], tblinvoicedetails.cashdiscount, tblinvoicedetails.netunitprice, tblinvoicedetails.totalprice, tblinvoicehead.invoicetype" _ & "from (tblcustomers inner bring together tblinvoicehead on tblcustomers.accountnumber = tblinvoicehead.customernumber) inner bring together tblinvoicedetails" _ & "on tblinvoicehead.invoicenumber = tblinvoicedetails.invoicenumber" _ & "where (((tblinvoicehead.invoicenumber) between " & strfrom & " , " & strto & "))" set qd = currentdb.createquerydef("repinv", strsql) set rs = qd.openrecordset 'docmd.openquery "repinv", strsql reports!repinvoicetest.recordsource = "repinv" docmd.openreport "repinvoicetest", acviewpreview end sub

`

usually error "missing parameter" means spelled 1 of columns wrong. if take sql , paste new query (temp, don't save) , run it, misspelled column pop window asking provide value "parameter" (because msaccess assuming never misspell column name).

in query above, might have copy/pasted wrong, if not, don't have plenty spaces between words go on them on next line. instance, sql string end having stuff in "invoicetypefrom", because didn't have (necessary) space in there.

try query instead:

strsql = "select tblinvoicehead.customernumber, " _ & " tblcustomers.accountname,tblcustomers.address, " _ & " tblcustomers.phone1, tblcustomers.phone2, " _ & " tblcustomers.mobile1, tblcustomers.mobile2, tblinvoicehead.invoicenumber, " _ & " tblinvoicehead.invoicedate, tblinvoicehead.totalinvoice, " _ & " tblinvoicehead.cashdiscount, tblinvoicedetails.item, tblinvoicedetails.unit, " _ & " tblinvoicedetails.qtn, tblinvoicedetails.price, " _ & " tblinvoicedetails.[discount%], tblinvoicedetails.cashdiscount, " _ & " tblinvoicedetails.netunitprice, tblinvoicedetails.totalprice, " _ & " tblinvoicehead.invoicetype " _ & " (tblcustomers inner bring together tblinvoicehead " _ & " on tblcustomers.accountnumber = tblinvoicehead.customernumber) " _ & " inner bring together tblinvoicedetails " _ & " on tblinvoicehead.invoicenumber = tblinvoicedetails.invoicenumber " _ & " (((tblinvoicehead.invoicenumber) between " & strfrom & " , " & strto & "))"

notice how added lot of unncessary spaces @ begining , end of each line. of spaces ignored. however, if there few, errors. simple trick stick-with.

sql ms-access

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -