If > Now() +4

B

Bonnie

Hi there! Using A02 in XP. Trying to limit folks to keep
dates within a minimum. On my BeforeUpdate event I have:

If Me.DateDep > Now() + 4 Then
MsgBox "You cannot enter a deposit date greater than 4
days from today. Please check your data."
DoCmd.CancelEvent
Exit Sub
End If

I'm getting a "The value you entered isn't valid for this
field..." Should I use Date() rather than Now()?

My main goal is to limit dates to a few before and or a
few after Now() to avoid data entry errors for the year
2024 or 1004. Any advice where or what is best to use for
this?

Thanks in advance for any help or advice! I LUV U GUYS!!!
 
C

Chris Nebinger

Replace:
DoCmd.CancelEvent
With:
Cancel = True


That should take care of the issue.

Chris Nebinger
 
F

fredg

Hi there! Using A02 in XP. Trying to limit folks to keep
dates within a minimum. On my BeforeUpdate event I have:

If Me.DateDep > Now() + 4 Then
MsgBox "You cannot enter a deposit date greater than 4
days from today. Please check your data."
DoCmd.CancelEvent
Exit Sub
End If

I'm getting a "The value you entered isn't valid for this
field..." Should I use Date() rather than Now()?

My main goal is to limit dates to a few before and or a
few after Now() to avoid data entry errors for the year
2024 or 1004. Any advice where or what is best to use for
this?

Thanks in advance for any help or advice! I LUV U GUYS!!!

The problem with using Now() is that it includes a Time value.
Are you attempting to limit entries to 4 days from today or 4 days
from Today at 4:00 PM?

To keep entries within a full 4 day period of today, the following
should work in the DateDep field Before Update event
(IF [DateDep] is a Date datatype!!!).

If Me!DateDep > Date() + 4 Then
MsgBox "You cannot enter a deposit date greater than 4
days from today. Please check your data."
Cancel = True
End If

You could also use
If DateDiff("d",Date(),[DateDep]) > 4 Then
etc.

The Cancel = True will stop the Update and take the user back to the
[DateDep] control.
 
J

John Vinson

Hi there! Using A02 in XP. Trying to limit folks to keep
dates within a minimum. On my BeforeUpdate event I have:

If Me.DateDep > Now() + 4 Then
MsgBox "You cannot enter a deposit date greater than 4
days from today. Please check your data."
DoCmd.CancelEvent
Exit Sub
End If

I'm getting a "The value you entered isn't valid for this
field..." Should I use Date() rather than Now()?

Well, yes you should - but only because Now() does not return today's
date, it returns the current date and time to a few microseconds
accuracy.

Try

If CDate(Me!DateDep) > DateAdd("d", 4, Date())

and (as suggested elsethread) set Cancel to True rather than
DoCmd.CancelEvent. You may also want to check for dates in the past -
this expression will happily accept a DateDep of #4/19/1004#, since it
is prior to four days hence (just a bit further prior than you want!)
 
B

Bonnie

Thanks Chris. I learned that recently but need to replace
all my old instances. Thanks for the reminder.
 
B

Bonnie

John, thanks VERY much for your help and advice. I do
indeed plan to limit a prior date as well. I also need to
replace all my old cancelevents with cancel=true.

I hope you really understand that you guys are not just a
help but pretty much the reason for my learning how to
make my access db's work better and better. Maybe someday
I can work with a real programmer and take those last
steps. For now, all I have is what I can do myself, with
your help. Thanks again.
 
B

Bonnie

Thanks Fred! I REALLY appreciate you guys helping folks
like me in taking all our many baby steps. I was pretty
sure the Date vs Now was a problem.

Haven't used DateDiff much but will look at it. Thanks for
being willing to respond with your advice!
-----Original Message-----
Hi there! Using A02 in XP. Trying to limit folks to keep
dates within a minimum. On my BeforeUpdate event I have:

If Me.DateDep > Now() + 4 Then
MsgBox "You cannot enter a deposit date greater than 4
days from today. Please check your data."
DoCmd.CancelEvent
Exit Sub
End If

I'm getting a "The value you entered isn't valid for this
field..." Should I use Date() rather than Now()?

My main goal is to limit dates to a few before and or a
few after Now() to avoid data entry errors for the year
2024 or 1004. Any advice where or what is best to use for
this?

Thanks in advance for any help or advice! I LUV U
GUYS!!!

The problem with using Now() is that it includes a Time value.
Are you attempting to limit entries to 4 days from today or 4 days
from Today at 4:00 PM?

To keep entries within a full 4 day period of today, the following
should work in the DateDep field Before Update event
(IF [DateDep] is a Date datatype!!!).

If Me!DateDep > Date() + 4 Then
MsgBox "You cannot enter a deposit date greater than 4
days from today. Please check your data."
Cancel = True
End If

You could also use
If DateDiff("d",Date(),[DateDep]) > 4 Then
etc.

The Cancel = True will stop the Update and take the user back to the
[DateDep] control.
--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
.
 
M

Marshall Barton

Bonnie said:
Hi there! Using A02 in XP. Trying to limit folks to keep
dates within a minimum. On my BeforeUpdate event I have:

If Me.DateDep > Now() + 4 Then
MsgBox "You cannot enter a deposit date greater than 4
days from today. Please check your data."
DoCmd.CancelEvent
Exit Sub
End If

I'm getting a "The value you entered isn't valid for this
field..." Should I use Date() rather than Now()?

My main goal is to limit dates to a few before and or a
few after Now() to avoid data entry errors for the year
2024 or 1004. Any advice where or what is best to use for
this?


In addition to all the other thoughts in this thread, you
can check for a date that is either 4 days before or after
the current date all in one If:

If Abs(DateDiff("d", Me.DateDep, Date)) > 4 Then
MsgBox . . .
 

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

Similar Threads


Top