![]() |
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 |
Cancel = True
You're setting Cancel in a sub which has no reference to it: it's not a
global variable. Tim "Sam Kuo" wrote in message ... 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 |
All times are GMT +1. The time now is 04:21 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com