What am I doing wrong?

JeremySun

Board Regular
Joined
Jul 1, 2011
Messages
98
Please look at my code below. For some reason when the msgbox opens and the user closes it, the user has to click back into the textbox.. I know this is a simple fix but I can't think of it right now.
Code:
Private Sub txtfirstname_Change()
txtfirstname.Text = UCase$(Left(txtfirstname.Text, 1)) & LCase$(Mid$(txtfirstname.Text, 2))
txtfirstname.SelStart = Len(txtfirstname.Text)
 Dim lChr As Long
With Selection
   For lChr = 97 To 122
      .Replace Chr(lChr), UCase(Chr(lChr))
   Next lChr
End With
 
 If TypeName(Me.ActiveControl) = "TextBox" Then
        If ActiveControl = vbNullString Then Exit Sub
            If IsNumeric(ActiveControl) Then
                MsgBox "Sorry, text only"
                ActiveControl = vbNullString
                bNumbers = True
            End If
            End If
            End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Rich (BB code):
Private Sub txtfirstname_Change() txtfirstname.Text = UCase$(Left(txtfirstname.Text, 1)) & LCase$(Mid$(txtfirstname.Text, 2)) txtfirstname.SelStart = Len(txtfirstname.Text)  Dim lChr As Long With Selection    For lChr = 97 To 122       .Replace Chr(lChr), UCase(Chr(lChr))    Next lChr End With    If TypeName(Me.ActiveControl) = "TextBox" Then         If ActiveControl = vbNullString Then Exit Sub             If IsNumeric(ActiveControl) Then                 MsgBox "Sorry, text only"                 ActiveControl = vbNullString                 bNumbers = True
                Range("YourCell").Select
            End If             End If             End Sub
</pre>Though not pretty, would this fix the problem?
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,903
Members
452,948
Latest member
Dupuhini

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