MS Access Forum / Forms / August 2006
Close form without Updating
|
|
Thread rating:  |
Swifty - 30 Aug 2006 12:17 GMT I'm trying to create forms for adding data to tables, trouble is when you close the form, if there is anything in the text boxes it tries to update the table. I don't want closing the form to run an update, it would be useful if it asked first maybe, but not without confirmation but can't see how to stop it. I have tried adding a button to update, and another to close, but even my own close button is trying to update the table. I have also tried using code (below) as posted by someone else prior to an update to confirm whether or not data should be saved, but the form still then goes on to try to save even if you say no.
If MsgBox("Do you want to save the changes?", vbYesNo,"Confirm Change") = vbNo Then Cancel = True Me.Undo End If
Svetlana - 30 Aug 2006 14:00 GMT Instead of Me.Undo try DoCmd.RunCommand acCmdUndo
Swifty - 30 Aug 2006 14:11 GMT Thanks, unfortunately it is still trying to update. I'm only using the red cross at the top of the form and I just want it to discard everything and close, this only works if there are no entries on the form, as soon as there is anything on the form it tries to use it to update the table. Any other ideas?! :o)
> Instead of Me.Undo try DoCmd.RunCommand acCmdUndo Klatuu - 30 Aug 2006 14:16 GMT It is not your close button trying to do the update, it is the Close event of the form. Svetlana's suggestion will do the same thing. You need to move the code to the Unload event of the form.
> I'm trying to create forms for adding data to tables, trouble is when you > close the form, if there is anything in the text boxes it tries to update the [quoted text clipped - 11 lines] > Me.Undo > End If Swifty - 30 Aug 2006 14:26 GMT Hmmmmm, it's now producing more errors than before. It says the Undo command isn't available. I've put the code under the unload event. In fact, I can't even close the form when there's no data entered at all now.
> It is not your close button trying to do the update, it is the Close event of > the form. [quoted text clipped - 16 lines] > > Me.Undo > > End If Klatuu - 30 Aug 2006 14:31 GMT I forgot to mention, you first need to check to see if it needs updating:
If Me.Dirty Then If MsgBox("Do you want to save the changes?", vbYesNo,"Confirm Change") _ = vbNo Then Cancel = True Me.Undo End If
> Hmmmmm, it's now producing more errors than before. It says the Undo command > isn't available. I've put the code under the unload event. In fact, I can't [quoted text clipped - 20 lines] > > > Me.Undo > > > End If Swifty - 30 Aug 2006 14:38 GMT Hi again... Ok, I've put that in the unload, (and added another End If!), it now closes if there's nothing in the form again, but if there is any text, still tries to validate what's in the boxes against what should be in the table, complains if it fails the validation tests and says it cannot be saved do you still want to close, or updates it if validation succeeds. If someone starts making an entry and then wants to close the form and abandon what they were doing that doesn't seem unreasonable to me?
> I forgot to mention, you first need to check to see if it needs updating: > [quoted text clipped - 29 lines] > > > > Me.Undo > > > > End If Klatuu - 30 Aug 2006 15:01 GMT I missed that End If, thanks.
Where is the other validation occuring? How are you handling it? That could easily be the problem.
> Hi again... Ok, I've put that in the unload, (and added another End If!), it > now closes if there's nothing in the form again, but if there is any text, [quoted text clipped - 37 lines] > > > > > Me.Undo > > > > > End If Swifty - 30 Aug 2006 15:30 GMT The validation is on the table, if you try to enter a value which is not in the correct format it won't allow the entry. The point is, it shouldn't even be doing anything if you just want to close the form, if the data does look valid it saves it, I want it to just throw any values away, not start checking if they pass validation on the table field.
> I missed that End If, thanks. > [quoted text clipped - 42 lines] > > > > > > Me.Undo > > > > > > End If Klatuu - 30 Aug 2006 15:43 GMT This is exactly why I never use field or table level validation. You have very little control over it. I do all my validation in the form, either at the control or the form level. That way, I have control over whether it does it, how it does it, and when it does it. The only advantage to table/field validation, is that it is always consistent throughout the application.
> The validation is on the table, if you try to enter a value which is not in > the correct format it won't allow the entry. The point is, it shouldn't even [quoted text clipped - 48 lines] > > > > > > > Me.Undo > > > > > > > End If Swifty - 30 Aug 2006 15:53 GMT Oh well... i've removed the validation from the table, and it still wants to save before closing the form. Why can't it just discard what's been put on the form? It shouldn't even matter if it's valid data or Martian. I'm confused!
> This is exactly why I never use field or table level validation. You have > very little control over it. I do all my validation in the form, either at > the control or the form level. That way, I have control over whether it does > it, how it does it, and when it does it. The only advantage to table/field > validation, is that it is always consistent throughout the application. Klatuu - 30 Aug 2006 16:07 GMT That is what Me.Undo does. Here is a copy/paste directly from VBA Help on the Undo Method:
If the Undo method is applied to a form, all changes to the current record are lost. If the Undo method is applied to a control, only the control itself is affected.
There must be something else going on we are not seeing.
> Oh well... i've removed the validation from the table, and it still wants to > save before closing the form. Why can't it just discard what's been put on [quoted text clipped - 6 lines] > > it, how it does it, and when it does it. The only advantage to table/field > > validation, is that it is always consistent throughout the application.
|
|
|