Looping

Neo

Registered User.
Local time
Today, 12:10
Joined
Mar 5, 2003
Messages
42
I have a sub form which shows data of orders.

I want to have a button on the main form that will loop through the records in the sub form and check that there are no null values.

can some one explainm how to do this

thanks
 
You can try this.

Dim ctl As Control
For Each ctl In Me.<YouSubFormControlNameHere>.Form.Controls
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
If IsNull(ctl.Name) Then
MsgBox " ....."
ctl.SetFocus
Exit Sub
End If
End If
Next ctl
 
Last edited:
it almost works but still only check the first line
 
Sorry. Try this again.

Code:
Private Sub Command1_Click()
Dim ctl As Control
For Each ctl In Me.<YouSubFormControlNameHere>.Form.Controls
    If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
        If IsNull(ctl) Then
            MsgBox "No null allowed"
            Me.<YouSubFormControlNameHere>.SetFocus
            ctl.SetFocus
            Exit Sub
        End If
    End If
Next ctl
End Sub
 

Users who are viewing this thread

Back
Top Bottom