SweetingA
asked on
Recordset not working
Hello Experts,
The following recordset code is not working corrrectly.
The first record is copied multiple times instead of stepping through the records.
Can you help?
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("S ELECT * FROM qry_PDM_Questions WHERE " & Me.Filter)
rst.MoveFirst
Dim rstADD As DAO.Recordset
Set rstADD = CurrentDb.OpenRecordset("t bl_PDM_Res ults")
Do Until rst.EOF
strSaveCriteria = Me.txtPeriod & Me.txtSite & Me.txtFunction & Me.txtCell & Me.Question
rstADD.AddNew
rstADD("Period") = Me.txtPeriod
rstADD("Site") = Me.txtSite
rstADD("Function") = Me.txtFunction
rstADD("Cell") = Me.txtCell
rstADD("Question") = Me.Question
rstADD("Answer") = Me.Answer
rstADD("SaveCriteria") = strSaveCriteria
rstADD.Update
rst.MoveNext
Loop
rst.Close
rstADD.Close
Thanks
The following recordset code is not working corrrectly.
The first record is copied multiple times instead of stepping through the records.
Can you help?
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("S
rst.MoveFirst
Dim rstADD As DAO.Recordset
Set rstADD = CurrentDb.OpenRecordset("t
Do Until rst.EOF
strSaveCriteria = Me.txtPeriod & Me.txtSite & Me.txtFunction & Me.txtCell & Me.Question
rstADD.AddNew
rstADD("Period") = Me.txtPeriod
rstADD("Site") = Me.txtSite
rstADD("Function") = Me.txtFunction
rstADD("Cell") = Me.txtCell
rstADD("Question") = Me.Question
rstADD("Answer") = Me.Answer
rstADD("SaveCriteria") = strSaveCriteria
rstADD.Update
rst.MoveNext
Loop
rst.Close
rstADD.Close
Thanks
As I told you in the other question:
You cannot refer to the FORM fields - you must refer to the "rst" recordset object fields:
rstADD("Period") = rst("Period")
rstADD("Site") = rst("Site")
and so on. Obviously you'd have to change the values of the Fields to match the ones in your recordset.
You cannot refer to the FORM fields - you must refer to the "rst" recordset object fields:
rstADD("Period") = rst("Period")
rstADD("Site") = rst("Site")
and so on. Obviously you'd have to change the values of the Fields to match the ones in your recordset.
ASKER
When i do this i always get "item not found in this collection"....see below....i was a bit too hasty earlier, did not realise it was copying 23 identical records.
what do you mean by matching the values in the fields to the values in the recordset?
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("S ELECT * FROM qry_PDM_Questions WHERE " & Me.Filter)
rst.MoveFirst
Dim rstADD As DAO.Recordset
Set rstADD = CurrentDb.OpenRecordset("t bl_PDM_Res ults")
Do Until rst.EOF
strSaveCriteria = Me.txtPeriod & Me.txtSite & Me.txtFunction & Me.txtCell & Me.Question
rstADD.AddNew
rstADD("Period") = rst("txtPeriod")
rstADD("Site") = rst("txtSite")
rstADD("Function") = rst("txtFunction")
rstADD("Cell") = rst("txtCell")
rstADD("Question") = rst("Question")
rstADD("Answer") = rst("Answer")
rstADD("SaveCriteria") = strSaveCriteria
rstADD.Update
rst.MoveNext
Loop
rst.Close
rstADD.Close
what do you mean by matching the values in the fields to the values in the recordset?
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("S
rst.MoveFirst
Dim rstADD As DAO.Recordset
Set rstADD = CurrentDb.OpenRecordset("t
Do Until rst.EOF
strSaveCriteria = Me.txtPeriod & Me.txtSite & Me.txtFunction & Me.txtCell & Me.Question
rstADD.AddNew
rstADD("Period") = rst("txtPeriod")
rstADD("Site") = rst("txtSite")
rstADD("Function") = rst("txtFunction")
rstADD("Cell") = rst("txtCell")
rstADD("Question") = rst("Question")
rstADD("Answer") = rst("Answer")
rstADD("SaveCriteria") = strSaveCriteria
rstADD.Update
rst.MoveNext
Loop
rst.Close
rstADD.Close
what are the fields from query "qry_PDM_Questions "
you will be using those fields in your codes to add records to recordset rstAdd,
NOT the name of the textboxes..
you will be using those fields in your codes to add records to recordset rstAdd,
NOT the name of the textboxes..
can you upload a copy of your db..
or post the SQL statement of query "qry_PDM_Questions"
or post the SQL statement of query "qry_PDM_Questions"
ASKER
Hi Capricorn1,
Attached is a copy of relevant records - very rough but you'll get the idea
thanks
pdm---Copy.mdb
Attached is a copy of relevant records - very rough but you'll get the idea
thanks
pdm---Copy.mdb
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Does not add any records to table?
ASKER
My apologies works great, forgot i changed the name of the button.
Thankyou....and LSMConsulting for their earlier help
Thankyou....and LSMConsulting for their earlier help
it added 23 records to table tbl_PDM_Results
tblPDMResults.txt
tblPDMResults.txt
what do you want to happen?