If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Close form without Updating
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 |
#2
|
|||
|
|||
Close form without Updating
Instead of Me.Undo try DoCmd.RunCommand acCmdUndo
|
#3
|
|||
|
|||
Close form without Updating
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?! ) "Svetlana" wrote: Instead of Me.Undo try DoCmd.RunCommand acCmdUndo |
#4
|
|||
|
|||
Close form without Updating
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. "Swifty" wrote: 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 |
#5
|
|||
|
|||
Close form without Updating
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. "Klatuu" wrote: 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. "Swifty" wrote: 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 |
#6
|
|||
|
|||
Close form without Updating
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 "Swifty" wrote: 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. "Klatuu" wrote: 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. "Swifty" wrote: 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 |
#7
|
|||
|
|||
Close form without Updating
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? "Klatuu" wrote: 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 "Swifty" wrote: 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. "Klatuu" wrote: 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. "Swifty" wrote: 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 |
#8
|
|||
|
|||
Close form without Updating
I missed that End If, thanks.
Where is the other validation occuring? How are you handling it? That could easily be the problem. "Swifty" wrote: 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? "Klatuu" wrote: 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 "Swifty" wrote: 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. "Klatuu" wrote: 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. "Swifty" wrote: 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 |
#9
|
|||
|
|||
Close form without Updating
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. "Klatuu" wrote: I missed that End If, thanks. Where is the other validation occuring? How are you handling it? That could easily be the problem. "Swifty" wrote: 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? "Klatuu" wrote: 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 "Swifty" wrote: 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. "Klatuu" wrote: 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. "Swifty" wrote: 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 |
#10
|
|||
|
|||
Close form without Updating
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. "Swifty" wrote: 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. "Klatuu" wrote: I missed that End If, thanks. Where is the other validation occuring? How are you handling it? That could easily be the problem. "Swifty" wrote: 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? "Klatuu" wrote: 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 "Swifty" wrote: 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. "Klatuu" wrote: 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. "Swifty" wrote: 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 |
|
Thread Tools | |
Display Modes | |
|
|