Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default TextBox Validation - Time Format

Wondering if there is a simple solution to this one (I really hope so!). I
am using a serious of userforms to collect data and write it into the
spreadsheet, some of the data to be collected is in Time or Date format. I
have found a way to check the users entries as far as dates go, so they are
forced to enter hh/mm/yy, is there something similar does anybody know that I
can use to check the format of the time entries, ie hh:mm. I'm really
struggling with this one!

I know there are calendar and date pickers but with the number of fields
involved I just wanted to keep it simple - famous last words I know!

Thanks in advance to someone much more clever than I!
--
Zani
(if I have posted here, I really am stuck!)

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default TextBox Validation - Time Format

Assuming you want to check the value of a String variable (set by the
inputbox) called UserInput, here is one easy way to check:
If (UserInput like "*#:##") And IsDate(UserInput) Then...

(would be a little harder if you wanted to allow am/pm but for "military
time" the above should work)
--
- K Dales


"Zani" wrote:

Wondering if there is a simple solution to this one (I really hope so!). I
am using a serious of userforms to collect data and write it into the
spreadsheet, some of the data to be collected is in Time or Date format. I
have found a way to check the users entries as far as dates go, so they are
forced to enter hh/mm/yy, is there something similar does anybody know that I
can use to check the format of the time entries, ie hh:mm. I'm really
struggling with this one!

I know there are calendar and date pickers but with the number of fields
involved I just wanted to keep it simple - famous last words I know!

Thanks in advance to someone much more clever than I!
--
Zani
(if I have posted here, I really am stuck!)

  #3   Report Post  
Posted to microsoft.public.excel.programming
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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
format textbox to time ASU Excel Discussion (Misc queries) 3 June 7th 06 10:05 PM
Format a Userform textbox to Military time Christy Excel Programming 2 August 24th 05 10:15 PM
Format As TIME In A TextBox Minitman[_4_] Excel Programming 4 February 9th 05 12:55 AM
TextBox in UserForm with 24h time format Mika Excel Programming 1 February 1st 05 07:45 PM
textbox validation Beginner[_2_] Excel Programming 1 April 7th 04 07:46 PM


All times are GMT +1. The time now is 11:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"