textbox formatting questions

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

Guest

Hi!
How do you do the ff:
1. Format a textbox such that the text begins with a capital letter and the
rest are in small caps?
2. Format a textbox such that it follows the telephone number format?
3. Date format?

Need your help.

Rook
 
Hi Rook,

Try:

With TextBox1
.Value = StrConv(.Value, vbProperCase)
'Or
.Value = Format(.Value, "dd/mm/yy")
End With

I am not aware of a telehone number format, certainly, but you can use a
custom format of your choice
 
Hi Norman.

I tried what you suggested but everytime I key in the second character the
textbox automatically formats it. Did I miss anything in the property?

Thanks

Rook
 
Hi Rook,

Where did you put the code?

I tried using a CommandButton or the TextBox's Exit event:

'=============>>
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With TextBox1
.Value = StrConv(.Value, vbProperCase)
'Or
.Value = Format(.Value, "dd/mm/yy")
End With
End Sub
'<<=============
 
Hi Norman,

I put the code within a sub - see below (courtesy of Bob Phillips):

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
Dim fBackwards As Boolean
Const ctlPrev As String = "TextBox3"
Const ctlNext As String = "TextBox2"

Select Case KeyCode
Case vbKeyTab, vbKeyReturn, vbKeyDown, vbKeyUp
Application.ScreenUpdating = False
fBackwards = CBool(Shift And 1) Or (KeyCode = vbKeyUp)
If Application.Version < 9 Then ActiveSheet.Range("A1").Select
If fBackwards Then
ActiveSheet.OLEObjects(ctlPrev).Activate
Else
ActiveSheet.OLEObjects(ctlNext).Activate
End If
Application.ScreenUpdating = True
End Select
End Sub


Thanks

Rook
 

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