VBA Access: No value given for one or more required parameters -


i know, there lots of answers out there problem should trivial, did not find right one. here problem: open record set following select statement:

select twinecellar.produktnavn, twinecellar.land,   twinecellar.produkttype,  twinecellar.år,   twinecellar.antall, twinecellar.poeng,   twinecellar.picture, twinecellar.kr,   twinecellar.poengsum, twinecellar.sum twinecellar (((twinecellar.land)=forms!fmainview!list13)    , ((twinecellar.produkttype)=forms!fmainview!list15)) order twinecellar.poeng; 

in immidiate window see list 13 contains "france" , list 15 contains "red" when create new query statement, it's working, however, on rst.open gsstrquery error. gsstrquery contains select string.

here code:

dim conn adodb.connection dim rst adodb.recordset  set conn = currentproject.connection set rst = new adodb.recordset  rst.cursortype = adopendynamic rst.activeconnection = conn rst.open gsstrquery 

anybody out there idea issue?

when build sql string, concatenate "parameters" values string.

gsstrquery = "select twinecellar.produktnavn, twinecellar.land, " & _                 "twinecellar.produkttype,  twinecellar.år, " & _                 "twinecellar.antall, twinecellar.poeng, " & _                 "twinecellar.picture, twinecellar.kr, " & _                 "twinecellar.poengsum, twinecellar.sum " & _              "from twinecellar " & _              "where (((twinecellar.land)= '" & forms!fmainview!list13 & "') " & _                 "and ((twinecellar.produkttype)= '" & forms!fmainview!list15 & "')) " & _              "order twinecellar.poeng;" 

that way parameter values hard coded string before try open query.

(also note: added single quotes around parameters indicate strings.)

(also note: & _ line continuation vba sql string concatenates properly. allows have readable sql code that's nicely indented.)

________________________________

there way use current gsstrquery , assign parameters values ado recordset. (but find above replacement method easier read when going review code. drawback have rebuild sql string each time parameters change. overhead minimal non complicated queries.)

however, if want use ado parameters, can find useful description here.

hope helps :)


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -