Solved

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

Posted on 2013-06-19
9
516 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
9 Comments
 
LVL 48

Expert Comment

by:Rgonzo1971
ID: 39261637
Hi,

And if you put the line before Cancel = True

Regards
0
 
LVL 49

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
 

Author Comment

by:gdunn59
ID: 39262897
cactus_data:

I tried it both before and after, same issue.

Thanks,
gdunn59
0
 
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:gdunn59
ID: 39263511
Helen_Feddema:

Yes, it is.

Thanks,
gdunn59
0
 

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 49

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
 

Author Comment

by:gdunn59
ID: 39272078
cactus_data:

Ok.  I guess the way it is will work.

Thanks for your assistance.

gdunn59
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39272098
You are welcome!

/gustav
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now