+ Reply to Thread
Results 1 to 5 of 5

UserForm

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    UserForm

    Hi guys,

    Have a small problem.

    I have a userform that requires 2 fields to be filled into textboxes, one text and one numeric.
    I do a test to see if the correct is applied. Have a msgbox that pops up saying incorrect one filled in but as soon as I click ok on the popup msgbox, the userform closes.

    I just want the focus to move back to the userform so the user can fill in the correct value in the correct textbox.

    Please help...

    Thanks in advance
    Jacques


  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: UserForm

    You need to post the code. You must have something like Exit Sub in the message box code
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: UserForm

    
    Private Sub btnSolve_AddVar_Click()
    
    '=========================================
    '1. Obtain values of known variables
    
        varName = txtSolve_VarName.Value
        varValue = txtSolve_VarValue.Value
        
    '=========================================
    '2. Do check for errors
            
        'Error: See if text is text, numbers are numbers
        '--------------------------------------------------
    
        If Application.WorksheetFunction.IsText(varValue) Then myError (2)
        If Application.WorksheetFunction.IsNumber(varName) Then myError (2)
    
        'Rest of code if no error
    
    End Sub
    
    Sub myError(x)
    '=========================================
    'Error Handling - Variable
    '=========================================
    
    Dim response
        
    Select Case x
    
    Case "1"
    '1 refers to variable
    
        response = MsgBox("Please do not use 'R' or 'C' as a variable", vbSystemModal + vbInformation, "ACTOM - Incorrect Value Entered!")
        End
        
        btnvSolve_Reset_Click
    
    Case "2"
    '2 refers to text or numbers being used wrong
    
        response = MsgBox("Please ensure that the textbox has text and numbers in values", vbSystemModal + vbInformation, "ACTOM - Incorrect Value Entered!")
        End
    
    End Select
    
    End Sub

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: UserForm

    I can't see why the form should close unless there is something in btnvSolve_Reset_Click.

    I can't see why you use worksheet functions to check for numbers

    
    Option Explicit
    
    Private Sub CommandButton1_Click()
        With Me
            If Len(.TextBox1.Value) = 0 Then
                MsgBox "You must complete the box"
                Exit Sub
            End If
            If IsNumeric(.TextBox1.Value) Then
                MsgBox "It's a number"
            Else: MsgBox "It's text"
            End If
        End With
    End Sub

  5. #5
    Forum Contributor
    Join Date
    01-15-2010
    Location
    Jhb, South Africa
    MS-Off Ver
    2007, 2010, 2016
    Posts
    275

    Re: UserForm

    Hi Roy,

    Sorry for the late reply, have been occupied a bit.
    I'll give this a try thanks.

+ Reply to Thread

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