Close form without saving

BPBP

Registered User.
Local time
Yesterday, 16:43
Joined
Feb 27, 2009
Messages
64
Lets say I have 10 textbox on a data entry form. 1 or 2 textbox are for fields which has relationship on the "many" side.

I have a button for closing the form. If in the event i have already keyed in 5 or 6 textboxes(which means a new row has been created in the table and some fields already filled, and then i wish not to save the entire row. What can i put into the close form button for deleting the entire row that was just keyed?
 
Lets say I have 10 textbox on a data entry form. 1 or 2 textbox are for fields which has relationship on the "many" side.

I have a button for closing the form. If in the event i have already keyed in 5 or 6 textboxes(which means a new row has been created in the table and some fields already filled, and then i wish not to save the entire row. What can i put into the close form button for deleting the entire row that was just keyed?

I am not sure if I follow your first paragraph but to answer your question:
Code:
me.undo

Regards,
Tim
 
Or you could write to a temp table then commit the record using a save button you could create on the form.
 
Based on what you've given us, you shouldn't need anything on your close button. When you go to close the form the Form_BeforUpdate will fire.

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
 If Me.NewRecord Then
   If MsgBox("Would You Like To Save This Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save This Record ???") = vbNo Then
     Me.Undo
   End If
 End If
End Sub

Unless you've omitted something, this statement is not correct:
"I have a button for closing the form. If in the event i have already keyed in 5 or 6 textboxes(which means a new row has been created in the table and some fields already filled, and then i wish not to save the entire row. What can i put into the close form button for deleting the entire row that was just keyed?"

Nothing is created in the table until the new record is saved.
 
As you say in your sig "ALWAYS more then one way to skin a cat" yours is the elegant solution :) and true....
 
Based on what you've given us, you shouldn't need anything on your close button. When you go to close the form the Form_BeforUpdate will fire.

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
 If Me.NewRecord Then
   If MsgBox("Would You Like To Save This Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save This Record ???") = vbNo Then
     Me.Undo
   End If
 End If
End Sub

Unless you've omitted something, this statement is not correct:


Nothing is created in the table until the new record is saved.


I didnt put it into the the form before update event as i have other buttons that adds new records and I dunt want this to fire everytime the other buttons are clicked.

I put your code into the on_click event of my close button. It works but there is slight problem, regardless whether it is a new record or not, it will fire. It works fine though, if placed in the form before update event.

I think its something to do with the If "Me.NewRecord part" is incorrectly referenced in my case. How do i get around this? Here's the code.

Private Sub ctrExitButton_Click()
On Error GoTo Err_ctrExitButton_Click

If Me.NewRecord Then
If MsgBox("Would You Like To Save TRF: " & Me.[Job No] & " ???", vbQuestion + vbYesNo + vbDefaultButton1, "Save This Record ???") = vbNo Then
Screen.ActiveForm.Undo
End If
End If

DoCmd.Close

Exit Sub
Exit_ctrExitButton_Click:
Exit Sub
Err_ctrExitButton_Click:
MsgBox Err.Description
Resume Exit_ctrExitButton_Click

End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom