VBAmalta89
Board Regular
- Joined
- Mar 25, 2011
- Messages
- 116
I have the following lines of code but when I compile it an error is prompted saying that it couldnt find the specified object and highlights this line:
For Each Ctrl In Me.Controls("Frame" & i).Controls
The coding im using is as follows:
Private Sub FactoryNum_Change()
OnlyNumbers
Dim i As Long
Dim Ctrl As Control
If (Val(FactoryNum.Value)) > 2 Then
MsgBox "Sorry, maximum of 2 plants allowed for Calculator"
For i = 1 To Val(FactoryNum.Text)
For Each Ctrl In Me.Controls("Frame" & i).Controls
Ctrl.Enabled = True
Next Ctrl
Next i
For i = Val(FactoryNum.Text) + 1 To 2
For Each Ctrl In Me.Controls("Frame" & i).Controls
Ctrl.Enabled = False
Next Ctrl
Next i
End If
End Sub
What i want the program to do is check that the value of a text box isnt greater than 2. if it is then it prompts the user to re enter a value, if it is less then program execution can continue.
How can i achieve this?
For Each Ctrl In Me.Controls("Frame" & i).Controls
The coding im using is as follows:
Private Sub FactoryNum_Change()
OnlyNumbers
Dim i As Long
Dim Ctrl As Control
If (Val(FactoryNum.Value)) > 2 Then
MsgBox "Sorry, maximum of 2 plants allowed for Calculator"
For i = 1 To Val(FactoryNum.Text)
For Each Ctrl In Me.Controls("Frame" & i).Controls
Ctrl.Enabled = True
Next Ctrl
Next i
For i = Val(FactoryNum.Text) + 1 To 2
For Each Ctrl In Me.Controls("Frame" & i).Controls
Ctrl.Enabled = False
Next Ctrl
Next i
End If
End Sub
What i want the program to do is check that the value of a text box isnt greater than 2. if it is then it prompts the user to re enter a value, if it is less then program execution can continue.
How can i achieve this?