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?
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.
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Visitor Forum.