I'm creating a MS Access report. I came across a small issue and I have no idea where it's going wrong. So what I'm trying to do is
1) Select everything from a query (query requires "TO" and "FROM" dates. I pass these values to the frmX which then gets referenced in the query). When i run a query by itself with the frmX open - it runs fine. 2) Im trying to change some values in the data 3) Insert the new values into tempTable1
Here's my code:
dim rs1 as DAO.Recordset
dim rs2 as DAO.Recordset
CurrentDb.Execute "DELETE FROM [tempProvider-Detail]"
'Repopulating temp table
DoCmd.OpenQuery "qryProvider-FINAL"
'Input Source
Set rs1 = CurrentDb.OpenRecordset("Select * from [qryProvider-Final]", , dbOpenSnapshot)
'Target Source
Set rs2 = CurrentDb.OpenRecordset("Select * from tempProvider-DETAIL", dbOpenDynamic)
What's interesting here is that it does not hang up on DoCMD.OpenQuery - however when I get to set rs1...... then it tells me that it expects 2 parameters. I don't know why - since the query already opened - and it works fine when I try opening it by itself it opens (with dates in frmX that i reference in the query).
Please help me out!
So I did this as Heinzi helped me.. still getting same error What is wrong??????
DoCmd.OpenQuery "qryProvider-FINAL"
Set qdf = CurrentDb.QueryDefs("qryProvider-FINAL")
qdf.Parameters(0) = [Forms]![frmX]![txtFrom]
qdf.Parameters(1) = [Forms]![frmX]![txtTo]
Set rs1 = qdf.OpenRecordset
strSQL = "SELECT * FROM [qryProvider-FINAL];"
'Input Source
Set rs1 = CurrentDb.OpenRecordset(strSQL, , dbOpenSnapshot) ---this is where it hangs up
rs1in line 6, no need to open it again).qdf.OpenRecordsetwill not return all data?