Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default textbox - format for dates (mm/dd/yyy)

I have a text box in a userform. The box will be used to manually ente
a date, so I would like the "/" to appear between the month & day
year as the date is entered as well as not allow invalid date entries.


B

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default textbox - format for dates (mm/dd/yyy)

Hi BA,

There are several ways to do this. The best may be to use a specialized
control instead of a TextBox...perhaps the Date/Time Picker. But you'll
have to check licensing requirements and availability on client machines
before using one.

If you want to use a textbox, you could put some code behind it like this:

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With TextBox1
If IsDate(.Text) Then
.Text = Format$(.Text, "Short Date")
Else
.SelStart = 0
.SelLength = Len(.Text)
MsgBox "Invalid date entered.", vbExclamation
Cancel = True
End If
End With
End Sub


If you want the /'s to show up, then it would be somewhat trickier. Your
best bet in that case may be to use 3 separate textboxes separated by labels
with captions of "/". Then you could validate the concatenation of the
textboxes assuming all three are filled in. If all three aren't filled in,
you can raise an error when they attempt to proceed.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


barrfly wrote:
I have a text box in a userform. The box will be used to manually
enter a date, so I would like the "/" to appear between the month &
day & year as the date is entered as well as not allow invalid date
entries.


BA


---
Message posted from http://www.ExcelForum.com/


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
TextBox format? Pas Excel Discussion (Misc queries) 5 April 25th 10 11:13 PM
TextBox format? AOU Excel Discussion (Misc queries) 4 June 12th 07 11:24 PM
TextBox Format grahammal Excel Discussion (Misc queries) 3 March 29th 06 01:35 PM
Format Textbox as % Todd Huttenstine[_2_] Excel Programming 2 December 15th 03 12:07 AM
Format textbox for dates Lieven Mettepenningen Excel Programming 2 October 15th 03 03:58 PM


All times are GMT +1. The time now is 02:31 PM.

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

About Us

"It's about Microsoft Excel"