ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Dates (https://www.excelbanter.com/excel-programming/274720-re-dates.html)

Michael Langust

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



.



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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com