Hello
I'm new to this so any help will be greatly appreciated.
I'm trying to open a recordset on a query with a parameter. I understand the way to open a recordset on a query is with Querydef. So i did some searching and thought i had found the solution.....however
The below does not work:
Set appExcel = Excel.Application
Set wbk = appExcel.Workbooks.Open(sOutput)
Set wks = appExcel.Worksheets(cTabOne)
Set dbs = CurrentDb
Set QD1 = dbs.QueryDefs("qry_DeveloperandSites")
QD1.Parameters![SiteID] = "763322"
Set rst2 = QD1.OpenRecordset
when i try to run this the error message " Item not found in this collection"..
Now SiteID does exist as i field in the "qry_DeveloperandSites" Query...Because i couldnt get to work with a parameter txtSiteID on a form i tried a literal value 763322 thinking if that works then just need to find out the syntax for referencing the field on an open form. Site Id is a text field so i have placed the correct delimiters round it as i understand it
Anyone understand what i have done wrong here?
Ultimately im creating two recordsets to transfer to excel the second recordset worked fine on a table but the first recordset on the query has caused me lots of problems
Please help
I'm new to this so any help will be greatly appreciated.
I'm trying to open a recordset on a query with a parameter. I understand the way to open a recordset on a query is with Querydef. So i did some searching and thought i had found the solution.....however
The below does not work:
Set appExcel = Excel.Application
Set wbk = appExcel.Workbooks.Open(sOutput)
Set wks = appExcel.Worksheets(cTabOne)
Set dbs = CurrentDb
Set QD1 = dbs.QueryDefs("qry_DeveloperandSites")
QD1.Parameters![SiteID] = "763322"
Set rst2 = QD1.OpenRecordset
when i try to run this the error message " Item not found in this collection"..
Now SiteID does exist as i field in the "qry_DeveloperandSites" Query...Because i couldnt get to work with a parameter txtSiteID on a form i tried a literal value 763322 thinking if that works then just need to find out the syntax for referencing the field on an open form. Site Id is a text field so i have placed the correct delimiters round it as i understand it
Anyone understand what i have done wrong here?
Ultimately im creating two recordsets to transfer to excel the second recordset worked fine on a table but the first recordset on the query has caused me lots of problems
Please help