Solved

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

Posted on 2013-06-19
9
571 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 50

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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

733 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