Proper Text in Userform Text Box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've built a fairly simple user form with text boxes and combo boxes that
inputs values onto a spreadsheet upon closing the userform with a command
button

Two of the text boxes are for Name and Surname.

How can I 'Proper' the text after the user has tabbed on to the next box or
closes the user form with the command button?
 
Frank

I put that line of code here: -

Private Sub txtClientfirstname_Change()
application.proper
End Sub

When I run the user form and tabbed to the next text box, it gave me an error.

I also have this code that is under cmdAdd_Click()

'check Firstname is filled in
If Trim(Me.txtClientfirstname.Value) = "" Then
Me.txtClientfirstname.SetFocus
MsgBox "Please enter the Client's Firstname"
Exit Sub
End If

Should the application.proper go somewhere here instead?

TIA
 
I think Frank meant something like this:

Option Explicit
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With Me.TextBox1
'.Value = Application.Proper(.Value)
'or
.Value = StrConv(.Value, vbProperCase)
End With
End Sub

(StrConv is built into VBA. Application.proper runs the worksheet function
=proper(). So it should be slightly (milliseconds??) slower.)

I used the _exit event so the value isn't changed until the user leaves the
textbox.
 
Alternative, just for the fun of it, it corrects while typing:

Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
TextBox1.Text = StrConv(TextBox1.Text, vbProperCase)
End Sub

HTH. Best wishes Harald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top