how can i use access pass through query to access sql sp -
i have store procedure has 4 paramater in sql, , want bulid applcation in access exec sp.
i have access form has 4 text box type pass through paramater , 1 button click , has code these
private sub command13_click() dim dbs dao.database dim qdf dao.querydef dim strsql string const c_strsql string = "exec sp_xcopy @curco={p1}, @curnumber={p2}, @newco={p3}, @newnumver={p4}" set dbs = currentdb set qdf = dbs.querydefs("querycopyvendor") strsql = replace(c_strsql, "{p1}", "forms!copyvendor!curco") strsql = replace(strsql, "{p2}", "forms!copyvendor!curnumber") strsql = replace(strsql, "{p3}", "forms!copyvendor!newco") strsql = replace(strsql, "{p4}", "forms!copyvendor!newnumber") qdf.sql = strsql qdf.execute set qdf = nothing set dbs = nothing end sub
but when submit, fellowing error:
run_time error '3065' cannot execute select query
does mean can not have select query in sp? please.
does mean can not have select query in sp?
no, error message telling access thinks query select query (or type of query returns records) , trying .execute
it. access doesn't because thinks should assigning returned records recordset
.
to create pass-through query (ptq) in dao must
- set
.connect
property of querydef @ leastodbc;
, and - set
.returnsrecords
propertyfalse
if not return rowset
here bare-bones code create ptq:
sub createptq() dim cdb dao.database, qdf dao.querydef set cdb = currentdb set qdf = cdb.createquerydef("ptq") qdf.connect = "odbc;" qdf.returnsrecords = false qdf.sql = "exec foo" qdf.close set qdf = nothing set cdb = nothing end sub
also, in code replacing placeholders names of form controls, e.g., ...
strsql = replace(c_strsql, "{p1}", "forms!copyvendor!curco")
...when should replacing placeholders controls' values...
strsql = replace(c_strsql, "{p1}", forms!copyvendor!curco)
...and remember if of parameters strings you'll need put quotes around them in exec
statement.