I am attempting to get a specific record from a table using DAO. Copy that record into a new dataset, modify that dataset and put back into the table as a new updated record. I am receiving a DataType Mismatch error when I try running through the For Loop when assigning the values to what will be the new updated record.
I am able to manually build the new recordset using variables but the problem is that I have tables that have way to many fields to do this effeciantly so I wanted to find a way to loop through the dataset and assign the fields.
Let me know if more information is needed and thanks for any assistance. Also, given what I want to do, I may be way off and am open to suggestions.
Dim rsOldField As Recordset
Dim rsNewField As Recordset
Dim fld As Field
Dim rsOldVisit As DAO.Recordset
Dim rsReturnVisit As DAO.Recordset
Set rsOldVisit = CurrentDb.OpenRecordset("SELECT * FROM tbl_visits WHERE [ptnumber] = '" & strptnumber & "' And [visit_type] = " & "'" & stricvisit & "'", dbOpenDynaset)
Set rsReturnVisit = CurrentDb.OpenRecordset("SELECT * FROM tbl_visits WHERE [ptnumber] = '" & strptnumber & "' And [visit_type] = " & "'" & stricvisit & "'", dbOpenDynaset)
For Each fld In rsReturnVisit.Fields
rsReturnVisit(fld.Name) = rsOldVisit(fld.Name)
Next
rsReturnVisit!Visit_Date = Format(Now(), "mm/dd/yyyy")
rsReturnVisit!visit_type = "RV"
rstTo.Update
I am able to manually build the new recordset using variables but the problem is that I have tables that have way to many fields to do this effeciantly so I wanted to find a way to loop through the dataset and assign the fields.
Let me know if more information is needed and thanks for any assistance. Also, given what I want to do, I may be way off and am open to suggestions.
Dim rsOldField As Recordset
Dim rsNewField As Recordset
Dim fld As Field
Dim rsOldVisit As DAO.Recordset
Dim rsReturnVisit As DAO.Recordset
Set rsOldVisit = CurrentDb.OpenRecordset("SELECT * FROM tbl_visits WHERE [ptnumber] = '" & strptnumber & "' And [visit_type] = " & "'" & stricvisit & "'", dbOpenDynaset)
Set rsReturnVisit = CurrentDb.OpenRecordset("SELECT * FROM tbl_visits WHERE [ptnumber] = '" & strptnumber & "' And [visit_type] = " & "'" & stricvisit & "'", dbOpenDynaset)
For Each fld In rsReturnVisit.Fields
rsReturnVisit(fld.Name) = rsOldVisit(fld.Name)
Next
rsReturnVisit!Visit_Date = Format(Now(), "mm/dd/yyyy")
rsReturnVisit!visit_type = "RV"
rstTo.Update