Loop Problem

  • Thread starter Thread starter Graham
  • Start date Start date
G

Graham

Hi,

Having problem with the following code. Can you please
show me what and where i place coding to stop when it is
at the end of records in my subform called "WagesImput
Input Query"

Hope you understand my problem.

Thanks


DoCmd.GoToControl "WagesImput Input Query"
DoCmd.GoToRecord acActiveDataObject, , acFirst
DoCmd.GoToControl "Check"
Bosst1 = 0
notick = 0
twotick = 0
Bosst1 = 0

Do

Bosst1 = Bosst1 + 1

Select Case check ' Evaluate Number.

Case -1 ' OK Just one Box Ticked

Case 0 'No Box is ticked
notick = notick + 1

Case Else 'More Than 1 Box Ticked
twotick = twotick + 1
End Select

DoCmd.GoToRecord acActiveDataObject, , acNext

Loop
 
Hi Graham, you need to loop while not at a new record
i.e.

Do While Not Me![WagesImput Input Query].Form.NewRecord
' Note: I didn't test this statement

....

Loop


I don't know your situation, but it's usually better practice to work with a
recordset clone:

e.g.

Dim frm as Form
Dim rst as DAO.Recordset

Set frm = [WagesImput Input Query].Form ' [WagesImput Input Query] is the
name of the subform.
Set rst = frm.RecordsetClone ' Get a copy of the subform's current
recordset

If rst.RecordCount >= 1 then
rst.MoveFirst ' Point a t forst record in clone
End If

' Loop through the recordset
Do While Not rst.EOF

Bosst1 = Bosst1 + 1

Select Case rst("check") ' modify as required to

Case -1 ' OK Just one Box Ticked

Case 0 'No Box is ticked
notick = notick + 1

Case Else 'More Than 1 Box Ticked
twotick = twotick + 1
End Select

rst.MoveNext
Loop

Hope this helps, Graeme
 
Back
Top