-
OK if i want to format a textbox so 'currency' or 'date' or something else where is it best to do it, such as under txt_GotFocus or txt_Change or something else so that it stays that when it is changed and saved like that?? PS Could you throw in the format for PhoneNumber?
-
I reckon either in LostFocus or trapping a return key press would be as good a place as any!
eg:
Code:
Private Sub text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
text1.Text = format(...... text1.Text etc)
End If
End Sub
------------------
Mark Sreeves
Analyst Programmer
[email protected]
A BMW Group Company
-
lost focus would probably be better
you could do both though...
------------------
Mark Sreeves
Analyst Programmer
[email protected]
A BMW Group Company
-
Thanks for all the input. I am learning quick by chatting on VB World, I love it.
-
I use LostFocus to format the text box;
Sub TextBox1_LostFocus
Textbox1.Text=Format(TextBox1.Text,"Currency")
End sub
Note: If it's currency I tend to use the GotFocus event to return it to a double for easy editing;
Sub Textbox1_GotFocus
TextBox1.Text=Cdbl(TextBox1.Text)
End Sub
As for phone numbers, DO NOT attempt to format them - there is no guaranteed formatting for phone numbers. For example, a load of phone numbers in the UK have just changed (this is about the third change we've had in the last few years), so you never can be sure that they will stay the same.
------------------
Mark "Buzby" Beeton
VB Developer
[email protected]
[This message has been edited by Buzby (edited 02-03-2000).]
-
The problem with capturing a key press or the changed event is that if you use the standard :
format(string, style)
then it will fill the rest of the text with with the style. I really haven't been able to make it work there. Generally what I'll do is capture the lost focus. I could be wrong about the other, I've just never got it to work right.