Solved Force form to close (1 Viewer)

Number11

Member
Local time
Today, 10:24
Joined
Jan 29, 2020
Messages
607
Hi, So i have a form that has a disregard button on and i use this code

Me.Undo
DoCmd.Close acForm, Me.Name

to undo and close form. However I have added because one of the field within the form has an after update event which is looking for a date change it asks the user to revert the date back to what it was before closing the form if possible, i would like to button to ignore everything any ideas?
 

Ranman256

Well-known member
Local time
Today, 06:24
Joined
Apr 9, 2015
Messages
4,339
To close the form you are on only need: 'docmd.close'
Closing a form will save all changes,but the undo should revert back to the unEdited data.

What I do is let the user edit and 'unbound' record that way they dont edit live data.
The save button will run an update query to the live record.
 

Number11

Member
Local time
Today, 10:24
Joined
Jan 29, 2020
Messages
607
To close the form you are on only need: 'docmd.close'
Closing a form will save all changes,but the undo should revert back to the unEdited data.

What I do is let the user edit and 'unbound' record that way they dont edit live data.
The save button will run an update query to the live record.

Thanks for your thought, the close does not close until the user changes the date back manually, due to the after update event, if they do form closes so looking for a way so the form closes without the user needing to manual change the date back :(
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:24
Joined
May 7, 2009
Messages
19,175
add a form-wise Boolean variable.
on the click event of the disregard button, set the value of the variable to True.
on the after_update event, check the value of the variable.
if it is set to True, ignore the rest of the code.
otherwise, revert the date.
 

Number11

Member
Local time
Today, 10:24
Joined
Jan 29, 2020
Messages
607
add a form-wise Boolean variable.
on the click event of the disregard button, set the value of the variable to True.
on the after_update event, check the value of the variable.
if it is set to True, ignore the rest of the code.
otherwise, revert the date.

Thanks for your time, so i need to add this to the event?

disregards button:
Dim MyVar as Boolean
MyVar= Variable

After Update Event:
Dim MyVar as Boolean
MyVar= True

seems just to cause errors :(
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:24
Joined
May 7, 2009
Messages
19,175
if you can share the form (together with table if the form is bound) on a sample db, so I can give you the sample.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:24
Joined
May 7, 2009
Messages
19,175
I was unable to resolve the problem.
the reason is that when you edit the date field, the before update event will fire when you leave the form when clicking the Disregard button.
try using unbound form as suggested by Mr.Ranman.
 

Number11

Member
Local time
Today, 10:24
Joined
Jan 29, 2020
Messages
607
I was unable to resolve the problem.
the reason is that when you edit the date field, the before update event will fire when you leave the form when clicking the Disregard button.
try using unbound form as suggested by Mr.Ranman.
Thanks i am unsure how to use the unbound form as suggested by Mr.Ranman.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:24
Joined
Oct 29, 2018
Messages
21,358
Hi. As Arnel said, the BeforeUpdate event fires first before the Click event of the Disregard button gets a chance to activate. Take a look at the attached modified version of your db and notice the following.

When you open the form and change the date to cause an error, you'll notice clicking your mouse on the Disregard button doesn't really click on it because the BeforeUpdate event is firing. So, in the attached version, you'll have to click on the Disregard button one more time, which this time, since the BeforeUpdate event is done executing, it should fire the Click event.

In other words, please try the following:
  1. Open the main form
  2. Change the date to cause the error
  3. Click on the Disregard button
  4. Click on the Disregard button again
Not sure if this solves your problem, but it might be an option if you can't find any other solution. If you do, though, please let us know. Cheers!
 

Attachments

  • Database2.zip
    39 KB · Views: 94

Number11

Member
Local time
Today, 10:24
Joined
Jan 29, 2020
Messages
607
Hi. As Arnel said, the BeforeUpdate event fires first before the Click event of the Disregard button gets a chance to activate. Take a look at the attached modified version of your db and notice the following.

When you open the form and change the date to cause an error, you'll notice clicking your mouse on the Disregard button doesn't really click on it because the BeforeUpdate event is firing. So, in the attached version, you'll have to click on the Disregard button one more time, which this time, since the BeforeUpdate event is done executing, it should fire the Click event.

In other words, please try the following:
  1. Open the main form
  2. Change the date to cause the error
  3. Click on the Disregard button
  4. Click on the Disregard button again
Not sure if this solves your problem, but it might be an option if you can't find any other solution. If you do, though, please let us know. Cheers!
Amazing job Thank you so much loving it ! :)
 

Users who are viewing this thread

Top Bottom