Solved

Enhancement to my Code to Check if a Date is Greater Than the Current Date

Posted on 2013-06-19
9
581 Views
Last Modified: 2013-06-24
I have code that checks a date in a field to see if it is less than or equal to the current date.  I have it on the BeforeUpdate Event of the Field, so the focus automatically goes back to this field, but the old date that the user entered is still sitting there.

After the cursor's focus is back in that field, I would like to have the field wipe out the old date (clear the field) and be blank and ready for the user to enter the correct date.

When I tried putting in the following line of code: me.Quality_Review_Date.value = ""

after the line of code "Cancel=True", I get run-time error '2115'.

Below is the code I'm using to check the Date field:
If Me.Quality_Review_Date.Value > (Date) Then
    MsgBox ("You must enter a date less than or equal to today's date!")
    Cancel = True
End If

Open in new window

What do I need to do to accomplish this?

Thanks,
gdunn59
0
Comment
Question by:gdunn59
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 39261637
Hi,

And if you put the line before Cancel = True

Regards
0
 
LVL 50

Accepted Solution

by:
Gustav Brock earned 300 total points
ID: 39261706
This will do:
If Me!Quality_Review_Date.Value > Date Then
    MsgBox ("Please enter a date less than or equal to today's date.")
    Me!Quality_Review_Date.Undo
    Cancel = True
End If

Open in new window

/gustav
0
 
LVL 1

Author Comment

by:gdunn59
ID: 39262897
cactus_data:

I tried it both before and after, same issue.

Thanks,
gdunn59
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 31

Expert Comment

by:Helen Feddema
ID: 39263124
Is the code running from the BeforeUpdate event of the textbox with the date?  That is where it should be.
0
 
LVL 1

Author Comment

by:gdunn59
ID: 39263511
Helen_Feddema:

Yes, it is.

Thanks,
gdunn59
0
 
LVL 1

Author Comment

by:gdunn59
ID: 39271992
cactus_data:

Sorry, I didn't see in your posting that you had put in the "Undo" command.  I pasted in your code from ID: 39261706, and it worked.  It places the cursor back in the Date field, with the date highlighted, the only thing is it doesn't wipe out the date that is already there.

Is there a way around this to have the field get wiped out all together?  If not, that's fine.  At least the field/date is highlighted and the user can just type and it will wipe out the existing date with the new date the user types in.

Thanks,
gdunn59
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 39272070
OK, that explains.

And no, Undo will not wipe out anything, just revert a change.

If that isn't enough, you will have to use the AfterUpdate event but this will, of course, only trig if data has been changed, and that is what you wish to prevent.

/gustav
0
 
LVL 1

Author Comment

by:gdunn59
ID: 39272078
cactus_data:

Ok.  I guess the way it is will work.

Thanks for your assistance.

gdunn59
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 39272098
You are welcome!

/gustav
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question