#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Dates

Many thanks Fred.

I suppose this is a frequently asked question as far
as .xls is concerned. Maybe Microsoft should think of
providing this feature in their future releases (??) of
having text boxes of date type; thereby avoiding lots of
unnecessary control by users.

br

-----Original Message-----
Micheal, below is code I often use when a Date input is

required. I assume
the userform has at least a Textbox, an OK button, and a

Cancel button.
All of the code is the userform code.

Goodluck
Fred


Private Sub OKButton_Click()
If ValidDate Then
Me.Tag = "OK"
Me.Hide
Else
MsgBox "The date is not valid. Please re-enter"
TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Value)
TextBox1.SetFocus
End If
End Sub

Private Sub CancelButton_Click()
Me.Tag = "Cancel"
Me.Hide
End Sub

Private Function ValidDate() As Boolean
If IsDate(TextBox1.Value) Then
TextBox1.Value = Format(CDate(TextBox1.Value), "d-

mmm-yyyy")
ValidDate = True
Else
ValidDate = False
End If
End Function

Private Sub TextBox1_AfterUpdate()
If ValidDate Then
TextBox1.Value = Format(CDate(TextBox1.Value), "d-

mmm-yyyy")
End If
End Sub




"Michael Langust" wrote in message
...
hi

I have a user form on which I want the users to enter

data
in date formats. The text box properties only seem to
allow text fields.

Thus, how do I do the following within a vb routine:
(a) convert input entered by user into a date type field
(b) validate that user has entered data that is a valid
date

Many thanks in anticipation

Micky



.

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
Linking computer dates (time) to spreadsheet dates that have formu bigisle Excel Worksheet Functions 3 January 3rd 10 08:05 PM
Stop dates from showing as numbers - when formated as dates JR Excel Discussion (Misc queries) 1 October 29th 08 04:38 PM
how do I sort a column of random dates into Consecutive dates Rob Gibson Excel Worksheet Functions 2 June 12th 07 05:10 AM
Identifying unique dates in a range of cells containing dates... cdavidson Excel Discussion (Misc queries) 4 October 13th 06 03:30 PM
Charting data against dates where dates are not at fixed intervals PK Charts and Charting in Excel 4 June 16th 05 05:08 AM


All times are GMT +1. The time now is 02:47 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"