Thread: InputBox a date
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_5_] Dave Peterson[_5_] is offline
external usenet poster
 
Posts: 1,758
Default InputBox a date

How about something like:

Option Explicit
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If IsDate(Me.TextBox1.Value) Then
Me.Label1.Caption = ""
Else
Me.Label1.Caption = "Please enter a date!"
Cancel = True
End If
End Sub

But if you really want more control, maybe using a calendar control would be
better.

Ron de Bruin has some info at:
http://www.rondebruin.nl/calendar.htm

At the bottom of that page is a link to a free calendar control.

Otto Moehrbach wrote:

I was able to do it by placing the value of the variable in a cell, then
setting the variable equal to the contents of that cell. In my particular
scenario that worked OK since I would be putting the variable into that cell
anyway.
But my question still stands. What is the best way to get a date from
an InputBox, either function or method. Thanks. Otto
"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
I want the user to respond to an InputBox with a date, like 1/1/05.
However, subsequent checks of this date against another date fail because
the Input date is a string.
I know that I can force the Input 1/1/05 into a date with the
DateSerial function. Is there a quicker, better way? The variable that
gets the Input date is declared a Variant.
Thanks for your help. Otto


--

Dave Peterson