Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-06-19
9
Medium Priority
?
602 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 53

Expert Comment

by:Rgonzo1971
ID: 39261637
Hi,

And if you put the line before Cancel = True

Regards
0
 
LVL 52

Accepted Solution

by:
Gustav Brock earned 1200 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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 52

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 52

Expert Comment

by:Gustav Brock
ID: 39272098
You are welcome!

/gustav
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

597 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