complie error:next without for

  • Thread starter Thread starter Walter
  • Start date Start date
W

Walter

The following code gives me the next without for error. What is wrong?

Dim c As Control

If Not Me.NewRecord Then
For Each c In Me.Controls
If c.Tag = "Vehicle" Or c.Tag = "Outsourced" Then
If IsNull(c) Then
c.Visible = False
Else
c.Visible = True
End If

Next c
 
You're getting that error because you are missing an End If inside the
For...Next loop. You're also missing a closing End If (at least in the
example you posted). Corrected code below;

Dim c As Control

If Not Me.NewRecord Then
For Each c In Me.Controls
If c.Tag = "Vehicle" Or c.Tag = "Outsourced" Then
If IsNull(c) Then
c.Visible = False
Else
c.Visible = True
End If
End If

Next c
End If
 
Walter said:
The following code gives me the next without for error. What is wrong?

Dim c As Control

If Not Me.NewRecord Then
For Each c In Me.Controls
If c.Tag = "Vehicle" Or c.Tag = "Outsourced" Then
If IsNull(c) Then
c.Visible = False
Else
c.Visible = True
End If

Next c

You're missing an End If, following c.Visible = True
 
Back
Top