For each loop on subforms

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
 
N

news.east.earthlink.net

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top