My Loop Doesn't

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm sure that I'm just missing a small piece of the puzzle, but I'm not able
to figure out why the following code doesn't loop thru all the data in the
subform.

Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone

Do Until rs.EOF
Me!subReceiptsNotDeposited.Form!DepositControlNumber = Me!ControlNumber
rs.MoveNext
Loop

What I'm trying to do is enter the control number on the main form into all
the records' corresponding fields on the subform. It does work for the first
record only.
 
Unfortunately, I get the same result. The first record in the subform is
changed, but that is the only record that changes.
 
Jenny Barker said:
I'm sure that I'm just missing a small piece of the puzzle, but I'm
not able to figure out why the following code doesn't loop thru all
the data in the subform.

Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone

Do Until rs.EOF
Me!subReceiptsNotDeposited.Form!DepositControlNumber =
Me!ControlNumber rs.MoveNext
Loop

What I'm trying to do is enter the control number on the main form
into all the records' corresponding fields on the subform. It does
work for the first record only.

If this code is running on the main form, then rs is being set to the
main form's recordsetclone. Does that recordset contain only one
record? On top of that, your code inside the loop doesn't do any
navigation in the subform or its recordsetclone to set the value of the
field in multiple records. I'd think you wanted something like this:

With Me!subReceiptsNotDeposited.Form.RecordsetClone
If .RecordCount > 0 Then
.MoveFirst
Do Until .EOF
.Edit
!DepositControlNumber = Me!ControlNumber
.Update
.MoveNext
Loop
End If
End With
 
Thank you!

Dirk Goldgar said:
If this code is running on the main form, then rs is being set to the
main form's recordsetclone. Does that recordset contain only one
record? On top of that, your code inside the loop doesn't do any
navigation in the subform or its recordsetclone to set the value of the
field in multiple records. I'd think you wanted something like this:

With Me!subReceiptsNotDeposited.Form.RecordsetClone
If .RecordCount > 0 Then
.MoveFirst
Do Until .EOF
.Edit
!DepositControlNumber = Me!ControlNumber
.Update
.MoveNext
Loop
End If
End With


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top