How to make sure a field is formatted correctly?

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

Guest

I want to make sure a field is formatted correctly. When the user types in
the field called Speed, I would like for the data to be formatted as 50,35.
50 and 35 can be any random number. If the field is not formatted in this way
"00,00", I want to display an error message for them to correct it. Can
someone help me w/ some VBA code?
 
Lavatress said:
I want to make sure a field is formatted correctly. When the user types in
the field called Speed, I would like for the data to be formatted as 50,35.
50 and 35 can be any random number. If the field is not formatted in this way
"00,00", I want to display an error message for them to correct it. Can
someone help me w/ some VBA code?


You can use the text box's BeforeUpdate event to check the
way it was typed
If Me.textbox.Text Like "##,##" Then
'ok
Else
MsgBox "Must be in 00,00 format"
Me.textbox.Undo
Cancel = True
End If
 
Thank you so much! It is working perfectly!

Marshall Barton said:
You can use the text box's BeforeUpdate event to check the
way it was typed
If Me.textbox.Text Like "##,##" Then
'ok
Else
MsgBox "Must be in 00,00 format"
Me.textbox.Undo
Cancel = True
End If
 
Back
Top