Gustav Brock
gustav at cactus.dk
Sat Jun 7 09:53:12 CDT 2003
Hi Tim >> Can anyone tell me what I am doing wrong here? When I run >> this as a stand alone query, it runs fine but when its in >> the form as code, I get the error message >> "Run-time error 3061 Too few parameters. Expected 1" >> >> sqlWSName = "SELECT DISTINCT qryInvItemWrkSht.worksheet, " _ >> & "qryInvItemWrkSht.worksheet_desc " _ >> & "FROM qryWrkSht INNER JOIN qryInvItemWrkSht " _ >> & "ON qryWrkSht.[Item Number] = qryInvItemWrkSht.Item;" >> Set rstWSName = CurDb.OpenRecordset(sqlWSName) Probably, in one of the queries you select from, there is a reference to a form, like [Forms].[frmForm].[txtControl]. Avoid this or - if that's not possible - use Eval to set the value of the parameter: Set qry = CurDb.QueryDefs() qry.SQL = sqlWSName qry.Parameters(0).Value = Eval(qry.Parameters(0).Name) Set rstWSName = qry.OpenRecordset(sqlWSName) ... You may need to spell out the parameter explicitly. Like this example: sqlWSName = "PARAMETERS [Forms].[frmForm].[txtControl] Short; " _ & "SELECT DISTINCT qryInvItemWrkSht.worksheet, " _ ... /gustav