Results 1 to 7 of 7

Can I return focus to a Textbox when Validation fails as part of a Sub?

Threaded View

  1. #1
    Registered User
    Join Date
    03-25-2009
    Location
    San Jose
    MS-Off Ver
    Excel 2007
    Posts
    83

    Can I return focus to a Textbox when Validation fails as part of a Sub?

    As part of a UserForm I am Validating and Formatting in one pass. The problem I'm having is that when the Validation fails, I get the error message, and the focus moves on to the next text box.

    I want to trap the user in a loop until they have acceptable data


    Private Function CheckNum2(CurValue As String)
        
        On Error Resume Next
        Select Case True
            Case IsNumeric(CurValue)
                CheckNum2 = Format$(CurValue, "#,###.##")
            Case CurValue < 1
                MsgBox ("You must set a value of 1 or greater")
            Case Else
                MsgBox ("You must set a value of 1 or greater")
    
        End Select
    
    End Function
    Private Sub APV_Exit(ByVal Cancel As MSForms.ReturnBoolean)
        
        With APV
            .Text = CheckNum2(.Text)
        End With
        
    End Sub
    Last edited by D3Pratt; 04-28-2009 at 06:01 PM. Reason: Subject clarification

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1