Results 1 to 4 of 4

Thread: <Resolved> How to stop error message if cancel pressed

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    West Midlands, UK
    Posts
    33

    Resolved <Resolved> How to stop error message if cancel pressed

    I am using the code below to validate the entry in a text field:

    Private Sub txtHomeNotes_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Dim RespMsg
    If Len(txtHomeNotes.Value) > 150 Then
    RespMsg = MsgBox("Notes must not be more than 150 characters in length." & Chr(10) & "Please compress message", vbExclamation + vbOKOnly, "Notes Error")
    txtHomeNotes.SetFocus
    End If
    End Sub

    If the user has entered 151 or more characters in the notes box and then presses the cancel command button, the MsgBox is still displayed. Is there any way to detect that the Cancel command button has been pressed, therefore allowing me to supress the error message.

    I would prefer all validation to be done on exit from text box rather than upon pressing the OK command button, as I am using validation for several other text boxes as well. They all give the same problem.

    I am using VBA for Excel.
    Last edited by Borg2of6; Aug 12th, 2005 at 11:40 AM. Reason: to set resolved status

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width