For each loop on subforms

  • Thread starter Thread starter Andy
  • Start date Start date
A

Andy

Access 97.

I have a form with a subform (continuous forms).
I want to step through the subforms checking that the data entered is
acceptable.
I have tried a number of format of code including

Set frm = Forms("frmAssignLCN").Form("frmAssignLCN Subform")
For Each ctrl In frm.Controls

also

For Each frmSubForm In Application.Forms("frmAssignLCN")
Debug.Print frmSubForm.Name
If Forms![frmAssignLCN]![Subtable].Form![LCN] = "" Then
MsgBox "An LCN has been left blank", vbOKOnly, "Data Validation Error"
fValidate_formAssignLCN = False
End If

the latter only check the first subform in the continuous form, the former
gives a "Can't find field" error.

Any ideas, I'm stuck and I think that I have exhausted the help file.

Many Thanks as always.

Andy
 
Why not simply set a filter on the subform to display only records that do
not meet the acceptable criteria. That way you can move thru each record to
correct the information. Like so.
Code in on click event of button named say "cmdFindUnacceptableRecords"

If FilterOn = False Then

Forms("frmAssignLCN").Form("frmAssignLCN Subform").Filter = Your Criteria
Forms("frmAssignLCN").Form("frmAssignLCN Subform").FilterOn = True

Else

Forms("frmAssignLCN").Form("frmAssignLCN Subform").Filter = ""
Forms("frmAssignLCN").Form("frmAssignLCN Subform").FilterOn = False

End If
Now you have a command button that switches the subforms filter to all
records or records that need corrections.
HTH
 
Back
Top