Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cancel = True JustBreathe Excel Programming 4 April 9th 07 04:02 AM
why doesnt cancel=true always work? Duncan[_5_] Excel Programming 3 July 18th 06 08:48 AM
Another way to suppress print besides Cancel = True? mikeburg[_56_] Excel Programming 4 December 5th 05 02:49 PM
BeforeDoubleClick Cancel=True not working Reggie Excel Programming 1 September 20th 05 03:43 AM
Setting Cancel = True in WorkbookBeforePrint Tony Excel Programming 0 December 21st 03 10:37 PM


All times are GMT +1. The time now is 04:51 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"