business_analyst
Board Regular
- Joined
- Jun 5, 2009
- Messages
- 99
Hello All,
I'm having a bit of a problem understanding the logic behind For statements in VBA and I was hoping someone could clear it up for me. I was basically trying to recognize if there were any blank textboxes in a userform, and assign different actions accordingly. Here is my code:
The problem is, that the Elseif statement after the For loop is not being recognized. In other words, proceed = 1 is not being allocated for some reason. Why is only the proceed value within the For loop being read? How can I fix this issue? Any help would be greatly appreciated.
I'm having a bit of a problem understanding the logic behind For statements in VBA and I was hoping someone could clear it up for me. I was basically trying to recognize if there were any blank textboxes in a userform, and assign different actions accordingly. Here is my code:
Code:
Private Sub check(ByVal frmname As Object)
Dim ctl As Control
Dim test As Integer
test = 0
If test = 0 Then
For Each ctl In frmname.Controls
If Left(ctl.Name, 4) = "txt_" Then
If ctl.Value = "" Then
proceed = 0
Exit For
Else: test = 1
End If
End If
Next ctl
ElseIf test = 1 Then
proceed = 1
End If
End Sub