Please Help: Whats wrong with my For loop?
Thanks for the help john, But The "i" value is not imcrementing at "i = i +
1" line
the value always stays as "1". I inserted a break point at i = i + 1 and the
value of i always stays as 1. Am I missing something here?
Thanks in advance
"john" wrote:
Hi Sam,
without seeing the code you use to populate your textboxes, can only guess
the process you are using.
Assuming OP presses a commandbutton after entering their ID then as quick
idea, perhaps an approach like following may work for you?
You will note that I have added word €śStudent€ť in front of your textbox
names €śName & €śAddress€ť these words are reserved in excel and their use as
textbox names may give unexpected results.
Hope helps I am about catch train home!
Dim i As Integer
Private Sub CommandButton1_Click()
If Me.Student_Name.Text = "" Then
If i < 4 Then
MsgBox (" please re-enter Student Id number" & Chr(10) & Chr(10)
& _
"Attempt " & i)
i = i + 1
Me.Student_ID.SetFocus
Else
MsgBox ("Please enter your Student Data")
Me.Student_Name.Enabled = True
Me.Student_Address.Enabled = True
Me.Ph_No.Enabled = True
Me.Student_Name.SetFocus
i = 1
End If
End If
End Sub
Private Sub UserForm_Initialize()
i = 1
Me.Student_Name.Enabled = False
Me.Student_Address.Enabled = False
Me.Ph_No.Enabled = False
End Sub
--
jb
"sam" wrote:
With Me.StudentId.Value
Dim i As Integer
If Me.Name.Value = "" Then
For i = 1 To 3
MsgBox (" please re-enter Student Id number")
Exit For
Next i
Me.Name.Enabled = True
Me.Address.Enabled = True
Me.Ph_No.Enabled = True
End If
End with
I want the students to try inputing their ID 3 times before the Name,
Address and Ph_No fields are enabled for them to input.
Thanks in advance
|