Loop through a Control

A

Angel G

How do I loop in a specific control using For?
The name of my Control is called "Result"
I am trying the following with no luck, maybe because it is the end of the
day?

Dim counter As Integer
counter = 0
Dim ctl As Control
For Each ctl In Me!Result
If IsNull(ctl) Then counter = counter + 1
Next ctl
If counter > 0 Then
MyText = MsgBox("Counters: " & counter, vbCritical, "Test")
End If

Thanks in advance
 
K

Ken Snell \(MVP\)

Define "loop through a specific control".... it's not clear from your post
what you want to achieve.
 
A

Angel G

I have a subform that displays several records, but there is a specific
control I would like to check for null values.
If all are null, I want to delete the records otherwise leave them as they
are. So I am trying to use a FOR statement
See my code below.
Thanks
 
K

Ken Snell \(MVP\)

OK - you want to loop through the records and test the value of the control
in each record.

Dim counter As Long
counter = 0
With Me.RecordsetClone
.MoveFirst
Do While .EOF = False
counter = counter - IsNull(Me!Result.Value)
.MoveNext
Loop
End With
If counter > 0 Then MsgBox "Counters: " & counter, vbCritical, "Test"

--

Ken Snell
<MS ACCESS MVP>
 
A

Angel G

Thank you!
Blessings to you Ken!


Ken Snell (MVP) said:
OK - you want to loop through the records and test the value of the
control in each record.

Dim counter As Long
counter = 0
With Me.RecordsetClone
.MoveFirst
Do While .EOF = False
counter = counter - IsNull(Me!Result.Value)
.MoveNext
Loop
End With
If counter > 0 Then MsgBox "Counters: " & counter, vbCritical, "Test"
 
D

David W. Fenton

I have a subform that displays several records, but there is a
specific control I would like to check for null values.
If all are null, I want to delete the records otherwise leave them
as they are.

You don't want to loop through them at all. You want to execute a
SQL delete statement, which operates on a set of records.
 

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