Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default InputBox a date

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default InputBox a date

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



  #3   Report Post  
Posted to microsoft.public.excel.programming
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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default InputBox a date

Dave
Thanks for your response. However, I am using an IsDate check already
to check that the user did enter a "Date". Looking in Help at the IsDate
function, it states that the IsDate check only checks to see if the value
"can be converted to a date". IOW, it may well be a string and the IsDate
check will still be True. That is the crux of the problem I am having. The
user is entering a "Date" per the IsDate check, but a subsequent query to
compare that "Date" to the same real date comes up False.
Am I out in left field with this? I would appreciate your comments on
this. Thanks again. Otto
"Dave Peterson" wrote in message
...
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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default InputBox a date

You want to convert it to a date, too?

Option Explicit
Sub testme()
Dim myVal As Variant
Dim myDate As Date

myVal = "01/03/05"

If IsDate(myVal) Then
myDate = CDate(myVal)
MsgBox myDate
End If

End Sub



Otto Moehrbach wrote:

Dave
Thanks for your response. However, I am using an IsDate check already
to check that the user did enter a "Date". Looking in Help at the IsDate
function, it states that the IsDate check only checks to see if the value
"can be converted to a date". IOW, it may well be a string and the IsDate
check will still be True. That is the crux of the problem I am having. The
user is entering a "Date" per the IsDate check, but a subsequent query to
compare that "Date" to the same real date comes up False.
Am I out in left field with this? I would appreciate your comments on
this. Thanks again. Otto
"Dave Peterson" wrote in message
...
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


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default InputBox a date

Dave
That is exactly what I needed. How do you know all this stuff?? Thanks
for taking the time. Otto
"Dave Peterson" wrote in message
...
You want to convert it to a date, too?

Option Explicit
Sub testme()
Dim myVal As Variant
Dim myDate As Date

myVal = "01/03/05"

If IsDate(myVal) Then
myDate = CDate(myVal)
MsgBox myDate
End If

End Sub



Otto Moehrbach wrote:

Dave
Thanks for your response. However, I am using an IsDate check
already
to check that the user did enter a "Date". Looking in Help at the IsDate
function, it states that the IsDate check only checks to see if the value
"can be converted to a date". IOW, it may well be a string and the
IsDate
check will still be True. That is the crux of the problem I am having.
The
user is entering a "Date" per the IsDate check, but a subsequent query to
compare that "Date" to the same real date comes up False.
Am I out in left field with this? I would appreciate your comments
on
this. Thanks again. Otto
"Dave Peterson" wrote in message
...
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


--

Dave Peterson



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default InputBox a date

I've read the answers by other posters!

(I don't bother with footnotes anymore, though. <vbg)

Otto Moehrbach wrote:

Dave
That is exactly what I needed. How do you know all this stuff?? Thanks
for taking the time. Otto
"Dave Peterson" wrote in message
...
You want to convert it to a date, too?

Option Explicit
Sub testme()
Dim myVal As Variant
Dim myDate As Date

myVal = "01/03/05"

If IsDate(myVal) Then
myDate = CDate(myVal)
MsgBox myDate
End If

End Sub



Otto Moehrbach wrote:

Dave
Thanks for your response. However, I am using an IsDate check
already
to check that the user did enter a "Date". Looking in Help at the IsDate
function, it states that the IsDate check only checks to see if the value
"can be converted to a date". IOW, it may well be a string and the
IsDate
check will still be True. That is the crux of the problem I am having.
The
user is entering a "Date" per the IsDate check, but a subsequent query to
compare that "Date" to the same real date comes up False.
Am I out in left field with this? I would appreciate your comments
on
this. Thanks again. Otto
"Dave Peterson" wrote in message
...
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


--

Dave Peterson


--

Dave Peterson
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
Using Date in InputBox for criteria in code SMac Excel Programming 6 March 24th 05 07:48 PM
Using InputBox to get desired date for a Query pulling data from Access into Excel cbeebe[_6_] Excel Programming 0 November 4th 04 09:30 PM
Inputbox to enter date Tom Ogilvy Excel Programming 0 July 27th 04 05:44 PM
Inputbox as Date andibevan Excel Programming 3 July 9th 04 02:15 PM
Date from InputBox Michael Excel Programming 3 May 26th 04 01:11 PM


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