Selecting another Textbox

Rocky0201

Active Member
Joined
Aug 20, 2009
Messages
278
Hi,

I have a TextBox on my UserForm (TextBox119). I having difficulties selecting another TextBox once I validate the entry in TextBox119. I've reviewed many posts and tried many variations but to no avail. Whenever I enter a value and press enter or tab, the cursor goes to a ComboBox in the same Frame.
Code:
Private Sub TextBox119_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    
    With TextBox119
        If Not IsNumeric(.Text) And .Text <> "" Then
            '.Text = Left(.Text, Len(.Text) - 1)
            Msg = Msg & "Milestone Duration must be Numeric"
            Style = vbOKOnly '//Define buttons.
            Title = "Milestone Activation" '// Define title.
            '// Display message.
            Response = MsgBox(Msg, Style, Title)
           Else
            With TextBox126
                .Text = ""
                .SetFocus
            End With
        End If
    End With
    
End Sub

The TextBox'es are in Frame2 which Frame2 is in Multipage5, if this makes a difference.

Thanks for any help you can provide.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Thanks Mike for your response.

I did try Afterupdate, BeforeUpdate, and Exit. I changed my code to the following:

Code:
Private Sub TextBox119_Change()
    
    With TextBox119
        If Not IsNumeric(.Text) And .Text <> "" Then
            '.Text = Left(.Text, Len(.Text) - 1)
            Msg = Msg & "Milestone Duration must be Numeric"
            Style = vbOKOnly '//Define buttons.
            Title = "Milestone Activation" '// Define title.
            '// Display message.
            Response = MsgBox(Msg, Style, Title)
        End If
    End With
    
End Sub
Private Sub TextBox119_AfterUpdate()
    Me.TextBox126.SetFocus
End Sub
No matter what I've tried, it seems that the SetFocus is ignored except if I use _Change. However, if I use Change, then every time I enter a value, the Change event occurs. So, if I wanted to enter 10, the Change event will execute on the 1 and the 0.

Any addition suggestions would greatly be appreciated.

Thanks
 
Upvote 0
This worked for me.
Code:
Private Sub TextBox119_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    With TextBox119
        If IsNumeric(.Text & "0") Then
            TextBox126.Text = ""
            TextBox126.SetFocus
        Else
            MsgBox "Enter a Number"
            Cancel = True
        End If
    End With
End Sub

It may be that the With..EndWith in the OP are improperly nested.
TextBox126 is not a property of TextBox119. Therefore
Code:
With TextBox119
    '...
    With TextBox126
        '...
    End With
'...
End With
is improperly nested. Sometimes you can get away with improper nesting, sometimes not.
(With .Parent.Parent.TextBox126 would be proper nesting.)
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top