B
bhNish
I posted this in ...access.forms without replies so I thought this NG
might be more appropriate.
I have a form containing a subform in which I want to automatically
copy information from the form record to the subform record. The form
shows a record from a query of table1 and the subform shows data from
a query of table2 using the appropriate master/child link.
Within the event procedure for a button click, the code works ok for
the first record that it modifies, but the next record returns the error
"No Current Record" (runtime error 3021)
on the line where I enable Edit mode.
If I close the form and reopen it, the first time I enable Edit,
then make changes and then Update it's OK. The next record that I
try to Edit, I get the error.
I'm stumped... can anybody help me?
Here's the Button click event that calls the function, shown below:
' do for each record
Me.Recordset.MoveFirst
For i = 1 To Me.Recordset.RecordCount
' copy data from form data to subform record
rtnFlag = CompareFormFields(Me, Me.SubFormMemberTo.Form, True)
' goto next record
Me.Recordset.MoveNext
Next i
' enddo - for each record
Function CompareFormFields(form1 As Form, form2 As Form, copyFlag As Boolean) As Boolean
' if not all fields of form2 same as form1 then
... <blah> ...
ctrlSource= "someFieldName"
... <blah> ...
form2.Recordset.Edit ' error occurs here on 2nd attempt at Edit
form2.Recordset.Fields(ctrlSource) = form1.Recordset.Fields(ctrlSource)
form2.Recordset.Update
' end if
... <blah> ...
End Function
might be more appropriate.
I have a form containing a subform in which I want to automatically
copy information from the form record to the subform record. The form
shows a record from a query of table1 and the subform shows data from
a query of table2 using the appropriate master/child link.
Within the event procedure for a button click, the code works ok for
the first record that it modifies, but the next record returns the error
"No Current Record" (runtime error 3021)
on the line where I enable Edit mode.
If I close the form and reopen it, the first time I enable Edit,
then make changes and then Update it's OK. The next record that I
try to Edit, I get the error.
I'm stumped... can anybody help me?
Here's the Button click event that calls the function, shown below:
' do for each record
Me.Recordset.MoveFirst
For i = 1 To Me.Recordset.RecordCount
' copy data from form data to subform record
rtnFlag = CompareFormFields(Me, Me.SubFormMemberTo.Form, True)
' goto next record
Me.Recordset.MoveNext
Next i
' enddo - for each record
Function CompareFormFields(form1 As Form, form2 As Form, copyFlag As Boolean) As Boolean
' if not all fields of form2 same as form1 then
... <blah> ...
ctrlSource= "someFieldName"
... <blah> ...
form2.Recordset.Edit ' error occurs here on 2nd attempt at Edit
form2.Recordset.Fields(ctrlSource) = form1.Recordset.Fields(ctrlSource)
form2.Recordset.Update
' end if
... <blah> ...
End Function