S
Steve2005black
Hi
I am a newbie to VBA.
I have a UserForm with a Calendar and a TextBox. I wrote a procedure to
check the number entered in the TextBox do not exceed a limit. The
following function triggers the MsgBox and resets the TextBox1.Value to
0, even when the TextBox1.Value DO NOT exceed the limit set.
----
Private Sub TextBox1_AfterUpdate()
If TextBox1.Value > ((ActiveSheet.Range("$C$5").Value + 1)) -
Calendar1.Day Then
MsgBox "Leave cannot exceed " & ((ActiveSheet.Range("$C$5").Value +
1)) - Calendar1.Day & " days!", vbCritical, "Wrong number of leave"
TextBox1.Value = 0
End If
End Sub
----
Finally after a couple of hours I came with this solution and it works
the way I need. However I am curious why the first code didn't work.
Can someone please guide me?
----
Private Sub TextBox1_AfterUpdate()
Dim DateLimit As Integer
DateLimit = TextBox1.Value
If DateLimit > ((ActiveSheet.Range("$C$5").Value + 1)) -
Calendar1.Day Then
MsgBox "Leave cannot exceed " & ((ActiveSheet.Range("$C$5").Value +
1)) - Calendar1.Day & " days!", vbCritical, "Wrong number of leave"
TextBox1.Value = 0
End If
End Sub
I am a newbie to VBA.
I have a UserForm with a Calendar and a TextBox. I wrote a procedure to
check the number entered in the TextBox do not exceed a limit. The
following function triggers the MsgBox and resets the TextBox1.Value to
0, even when the TextBox1.Value DO NOT exceed the limit set.
----
Private Sub TextBox1_AfterUpdate()
If TextBox1.Value > ((ActiveSheet.Range("$C$5").Value + 1)) -
Calendar1.Day Then
MsgBox "Leave cannot exceed " & ((ActiveSheet.Range("$C$5").Value +
1)) - Calendar1.Day & " days!", vbCritical, "Wrong number of leave"
TextBox1.Value = 0
End If
End Sub
----
Finally after a couple of hours I came with this solution and it works
the way I need. However I am curious why the first code didn't work.
Can someone please guide me?
----
Private Sub TextBox1_AfterUpdate()
Dim DateLimit As Integer
DateLimit = TextBox1.Value
If DateLimit > ((ActiveSheet.Range("$C$5").Value + 1)) -
Calendar1.Day Then
MsgBox "Leave cannot exceed " & ((ActiveSheet.Range("$C$5").Value +
1)) - Calendar1.Day & " days!", vbCritical, "Wrong number of leave"
TextBox1.Value = 0
End If
End Sub