View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Leith Ross[_533_] Leith Ross[_533_] is offline
external usenet poster
 
Posts: 1
Default TextBox Validation - Time Format


Hello Zani,

Since you are using multiple User Forms, the best approach is to use a
macro in a module that can be shared. Place this code in a VBA module
and call it from your code as in the example.

Calling the Macro:
CheckTimeEntry Textbox1

Just replace Textbox1 with the name of the TextBox whose entry you want
to check. If you want to check a TextBox on another User Form, the User
Form doesn't need to be visible, but must be loaded in memory and you
need to use the Form name when calling the macro.

Checking a TextBox on another Form:
CheckTimeEntry UserForm2.TextBox1
_______________________________

Public Sub CheckTimeEntry(ByRef Text_Box As MSForms.TextBox)

Dim MyTime As Date

On Error GoTo InvalidEntry
MyDate = CDate(Text_Box.Text)

Exit Sub

InvalidEntry:
MsgBox "The time value you entered is not valid."
Text_Box.Text = ""

End Sub
_______________________________

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=508912