Case statement for dates not working

G

Guest

I have a data entry screen where the user is only suppose to enter a date
that is within this range "10/1/2002 to 9/30/2005".

The case statement that I have just entered all takes such as 2001, 2000 or
2006,2008. I don;t want this. Just the dates in the date range that I
specify aboved.

Here is the case statement:

Dim TextDate As Date
TextDate = DateSerial(Right(Me!INDPTDOS.Value, 4), _
Left(Me!INDPTDOS.Value, 2), _
Mid(Me!INDPTDOS.Value, 3, 2))
Select Case TextDate
Case Between #10/1/2002# And #9/30/2005#
' do nothing
Case Else
MsgBox "You have entered an invalid date."
Cancel = True
End Select

What can I do to get this working correctly. It's been a week now and I
haven't been able to master this yet.
 
R

Rick Brandt

melwester said:
I have a data entry screen where the user is only suppose to enter a
date that is within this range "10/1/2002 to 9/30/2005".

The case statement that I have just entered all takes such as 2001,
2000 or 2006,2008. I don;t want this. Just the dates in the date
range that I specify aboved.

Here is the case statement:

Dim TextDate As Date
TextDate = DateSerial(Right(Me!INDPTDOS.Value, 4), _
Left(Me!INDPTDOS.Value, 2), _
Mid(Me!INDPTDOS.Value, 3, 2))
Select Case TextDate
Case Between #10/1/2002# And #9/30/2005#
' do nothing
Case Else
MsgBox "You have entered an invalid date."
Cancel = True
End Select

What can I do to get this working correctly. It's been a week now
and I haven't been able to master this yet.

Case doesn't support BETWEEN the way you are using it.

Try...

Case #10/1/2002# To #9/30/2005#
 
G

Guest

Ok - I tried this and guess what it still doesn't work the way I want it.
It still takes dates before 10/1/2002 and dates after 9/30/2005.

I need to get it so that it will only take dates from 10/1/2002 through
9/30/2005.


Donna
 
R

Rick Brandt

melwester said:
Ok - I tried this and guess what it still doesn't work the way I
want it. It still takes dates before 10/1/2002 and dates after
9/30/2005.

I need to get it so that it will only take dates from 10/1/2002
through 9/30/2005.

I just tried the following...

Sub tst()
Dim TextDate As Date
TextDate = DateSerial(2005, 9, 30)

Select Case TextDate
Case #10/1/2002# To #9/30/2005#
' do nothing
Case Else
MsgBox "You have entered an invalid date."
'Cancel = True
End Select
End Sub

....with various values being substituted in the DateSerial line and it
worked exactly as expected. The dates 10/1/2002 and 9/30/2005 both worked
(as well as several in between) and any dates outside of that range brought
up the MsgBox.
 
G

Guest

Why does it work for you and not me?

I enter in say 09/25/2000 and the date takes which I don't want. It should
had come up with the error message. The same goes for 05/25/2008.

What dates are you typing in to check this?

Donna
 
R

Rick Brandt

melwester said:
Why does it work for you and not me?

I enter in say 09/25/2000 and the date takes which I don't want. It
should had come up with the error message. The same goes for
05/25/2008.

What dates are you typing in to check this?

As I stated, I tried all dates immediately around the boundaries of the test
and a handful of others on both sides of the boundaries. All of them worked
as expected.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top