Computer Learning Zone CLZ Access Excel Word Windows

My favorite things in life don't cost any money. It's really clear that the most precious resource we all have is time.

-Steve Jobs
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Visitor Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
VBA error handling clear
Andrew G 

2 years ago
I am implementing error handling in my database to make it more user friendly.  I have some fields that have input masks (phone numbers/dates) and if an error appears, I want the text to be cleared.  This will make it easier for the user to reenter the data and/or allow them to exit the field without the form crashing.  To clear the String txtPhoneNumber field, in VBA I used txtPhoneNumber = ''.  However, I haven't had any luck clearing the Date and Number fields.  I tried:

txtDate = #1/1/1900#
-Run-time error -2137353567 (80020009)
oThe macro or function set to BeforeUpdate or ValidationRule property for this field is preventing Microsoft Access from saving the data in the field.

DoCmd.RunCommand acCmdUndo
-Run-time error '2046'
oThe command or action 'Undo' isn't available now.

Do you have any ideas or any suggestions on how I can clear the field?

Thank you.
Kevin Robertson  @Reply  
          
2 years ago
Try this. Doues it work for your needs?

    txtDate = Null
    txtDate.SetFocus
    txtDate.SelStart = 0


txtDate = Null will clear the date already in the field.
txtDate.SetFocus will set the focus back on the field.
txtDate.SelStart = 0 will place the cursor at the start of the Input Mask and display it.
Kevin Yip  @Reply  
     
2 years ago
Hi Andrew, do you want to clear the field or undo the user entry?  Your code indicates that you want to undo, and that is done differently.  If the Undo function "isn't available," it needs to be done some other way, such as using the .OldValue property.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Visitor Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/7/2026 11:21:22 AM. PLT: 1s