vba - Access SQL Enter Parameter Value when trying to export to excel -
i trying run sql statement , export result excel spread sheet. i've looked through the internet , found this, seemed work other users.
it runs asks me "enter parameter value" linking "selecteduser" on line 4 of code, message box shows @ point code starts here: docmd.transferspreadsheet. if click ok excel sheet created nothing in except titles selected columns tables in database. if put valid data text box , press ok, excel spreadsheet created correct data showing.
i know selected data in combobox been stored, because if message box shows selected data combobox.
any ideas anyone? it's obvious data isn't been passed through somewhere, can't see where.
private sub command12_click() dim strsql string dim strqry string dim selecteduser string dim db dao.database dim qdf querydef selecteduser = me.combo6.column(0) strsql = "select tblpra.prano, tblfolder.folder, tblfolder.fulltitle tblpra inner join (tblfolder inner join tblrelationship on tblfolder.folderid = tblrelationship.folderid) on tblpra.praid = tblrelationship.praid (((tblpra.prano)=selecteduser));" strqry = "tempuser" set db = currentdb set qdf = db.createquerydef(strqry, strsql) on error resume next docmd.deleteobject acquery, "strqry" docmd.transferspreadsheet acexport, acspreadsheettypeexcel8, _ strqry, "c:\users\prc93\desktop\test.xls", true docmd.deleteobject acquery, strqry end sub
the selecteduser
in query needs outside of quotes. string needs in single quotes 'selecteduser'
. if msgbox query , should see selecteduser
equals column (0)
. sure selecteduser
needs string , not number e.g. long
?
private sub command12_click() dim strsql string dim strqry string dim selecteduser string dim db dao.database dim qdf querydef selecteduser = me.combo6.column(0) strsql = "select tblpra.prano, tblfolder.folder, tblfolder.fulltitle " &_ "tblpra inner join (tblfolder inner join tblrelationship on " &_ "tblfolder.folderid = tblrelationship.folderid) on " &_ "tblpra.praid = tblrelationship.praid " &_ "where (((tblpra.prano)='" & selecteduser & "'));" strqry = "tempuser" set db = currentdb set qdf = db.createquerydef(strqry, strsql) on error resume next docmd.deleteobject acquery, "strqry" docmd.transferspreadsheet acexport, acspreadsheettypeexcel8, _ strqry, "c:\users\prc93\desktop\test.xls", true docmd.deleteobject acquery, strqry end sub
Comments
Post a Comment