Alright, let's get down to business, shall we?
There are 2 ways to solve this problem, the easy one, and the tricky one with a bit of work to be done. And also, both way have a little different end result. I have to leave the choices for you to make.
Solution #1
The first solution for Property not Found error is very easy and painless, and there is only one line of code to be done. The key is you can't use Cancel = True on BeforeUpdate event, but what you need is Docmd.CancelEvent. Below is the example code to solve this problem.
Private Sub objTricky_BeforeUpdate(Cancel As Integer) If condition is true Then Docmd.CancelEvent End If End SubThe end result of this solution: You have to pass the condition to continue. Otherwise, it will keep on with the event cancellation until the condition is success.
Solution #2
To get rid of Property not Found error in in the second way is a bit tricky. To solve this very problem, there are 3 little things to be made.
- Declare one global value on the form.
- Get rid of that Cancel = True code on BeforeUpdate event.
- You will need Me.Undo to save your problem, and you have to place the key solution on AfterUpdate event.
There you are, your problem of Property not Found should be resolved.
Let me show you how this works, in case my message doesn't convey well (my bad). Let me name my object (control or form) as objTricky and global variable as gv_continue for the sake of this example.
Originally, I would have my code like this when I have this problem:
Private Sub objTricky_BeforeUpdate(Cancel As Integer) If condition is true Then Cancel = True End If End Sub
To solve this problem, I came up with the modification version of the original code :
Dim gv_continue as Boolean Private Sub objTricky_BeforeUpdate(Cancel As Integer) If condition is true Then gv_continue = False Else gv_continue = True End If End Sub
Private Sub objTricky_AfterUpdate() If Not gv_continue Then ''--Add your message here if you like Me.Undo End If End Sub
The end result of this solution: The will undo all of the update you have made earlier when the condition fails.
That's it folks, pretty easy right? As I said the choices is yours, #1 or #2. I hope you will be able to resolve your Property not Found error as I have resolved mine.
That's it folks, pretty easy right? As I said the choices is yours, #1 or #2. I hope you will be able to resolve your Property not Found error as I have resolved mine.
0 comments:
Post a Comment