Formatting a string my own way

  • Thread starter Guus van Waardenburg
  • Start date
G

Guus van Waardenburg

Hi,

I have a string that I would like to automaticly format when the user exits
the textbox:

Private Sub TextBox7_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
TextBox7.Value = UCase(TextBox7.Value)
End Sub

Something like that. The string the user needs to put in = 1705 AB for
example. But some users will make a input like 1705ab or something else. How
can I alter my code so that at BeforUpdate my code always turns the string to
1705 AB? And how can I implement a warning if the input is way off like:
170555555

Best Regards!
 
J

Jean-Guy Marcil

Guus van Waardenburg was telling us:
Guus van Waardenburg nous racontait que :
Hi,

I have a string that I would like to automaticly format when the user
exits the textbox:

Private Sub TextBox7_BeforeUpdate(ByVal Cancel As
MSForms.ReturnBoolean) TextBox7.Value = UCase(TextBox7.Value)
End Sub

Something like that. The string the user needs to put in = 1705 AB for
example. But some users will make a input like 1705ab or something
else. How can I alter my code so that at BeforUpdate my code always
turns the string to 1705 AB? And how can I implement a warning if the
input is way off like: 170555555

You could use something like:

'_______________________________________
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)

If Len(Me.TextBox1.Value) > 7 Then
MsgBox "The text you entered is too long", vbInformation, "Wrong data"
Cancel = True
Else
Me.TextBox1.Value = UCase(Me.TextBox1.Value)
End If

End Sub
'_______________________________________

But you have to be a lot more specific regarding the conditions that have to
be met so that the entry is valid.

There are no known method that will check a string for "way offness"! ;-)

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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

Top