T
thdrought
Hi all,
I am having a problem with a database. What I am doing is providing a
button on a form which copies a recordset into a new recordset. When
it gets to the "For i...Next i" loop, I get an error that states
"Field Cannot be Updated". I suppose it's rstTo(i) that cannot be
updated and I don't understand why. Here is the code...
Private Sub ContinueCopy_Click()
Dim rstFrom As DAO.Recordset
Dim rstTo As DAO.Recordset
Dim i As Integer
Dim IngNewID As Long
If IsNull(Me.txtLoanNameChange) And IsNull(Me.txtClientNameChange)
Then
MsgBox "Please update at least one of the two fields in the
form."
Exit Sub
End If
Set rstFrom = Forms!Deals_Rework.Recordset
Set rstTo = Forms!Deals_Rework.RecordsetClone
rstTo.AddNew
For i = 1 To rstFrom.Fields.Count - 1
rstTo(i) = rstFrom(i)
Next i
IngNewID = rstTo(0) 'get the new loan ID
If IsNull(Me.txtLoanNameChange) = False Then
Forms!Deals_Rework.txtLoanName = Me.txtLoanNameChange
End If
If IsNull(Me.txtClientNameChange) = False Then
Forms!Deals_Rework.txtClientName = Me.txtClientNameChange
End If
DoCmd.Close
rstTo.Update 'move form to new record
rstFrom.Requery 're-load record set to show new record added
rstTo.FindLast "LoanID = " & IngNewID
Set rstFrom = Nothing
Set rstTo = Nothing
End Sub
Thanks,
Tom
I am having a problem with a database. What I am doing is providing a
button on a form which copies a recordset into a new recordset. When
it gets to the "For i...Next i" loop, I get an error that states
"Field Cannot be Updated". I suppose it's rstTo(i) that cannot be
updated and I don't understand why. Here is the code...
Private Sub ContinueCopy_Click()
Dim rstFrom As DAO.Recordset
Dim rstTo As DAO.Recordset
Dim i As Integer
Dim IngNewID As Long
If IsNull(Me.txtLoanNameChange) And IsNull(Me.txtClientNameChange)
Then
MsgBox "Please update at least one of the two fields in the
form."
Exit Sub
End If
Set rstFrom = Forms!Deals_Rework.Recordset
Set rstTo = Forms!Deals_Rework.RecordsetClone
rstTo.AddNew
For i = 1 To rstFrom.Fields.Count - 1
rstTo(i) = rstFrom(i)
Next i
IngNewID = rstTo(0) 'get the new loan ID
If IsNull(Me.txtLoanNameChange) = False Then
Forms!Deals_Rework.txtLoanName = Me.txtLoanNameChange
End If
If IsNull(Me.txtClientNameChange) = False Then
Forms!Deals_Rework.txtClientName = Me.txtClientNameChange
End If
DoCmd.Close
rstTo.Update 'move form to new record
rstFrom.Requery 're-load record set to show new record added
rstTo.FindLast "LoanID = " & IngNewID
Set rstFrom = Nothing
Set rstTo = Nothing
End Sub
Thanks,
Tom