Thread: Cancel = True
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sam Kuo[_3_] Sam Kuo[_3_] is offline
external usenet poster
 
Posts: 86
Default Cancel = True

I tried to use Cancel = Ture (as shown below) to ensure the user inputs a
value in 10 textboxes (namely txtCatchment1, txtCatchment2, ...,
txtCatchment10).
But my attempt returns an error at the line "Cancel=True". How should I fix
this?

' Below is in UserForm1
' (duplicate 10 times with the number changed to match the textbox name)
Private Sub txtCatchment1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
CheckInput(1)
End Sub

' Below is in Module1
Sub CheckInput(CatchmentNo As Long)
Dim strCatchmentNo As String
With UserForm1
strCatchmentNo = .Controls("txtCatchment" & CatchmentNo).Value
If Len(strCatchmentNo) 0 Then
Else
Cancel = True
MsgBox "You must enter a value",
vbOKOnly + vbExclamation, "Entry Required"
End If
End With
End Sub