question about "NOT" saving, when closing a data-entry form.

ion97

Registered User.
Local time
Today, 20:22
Joined
Feb 28, 2001
Messages
27
When I have a form in data entry mode, there is no way to close this form
once he started adding information to it. When I assign a macro to a button
with the command "Close" and SaveOnClose set to "No", the information added
is saved to the Table. Is there a way to get around this?
I mean, what the user enters the "data entry" form, starts adding
information and then changes his mind? Can't he close the form and
everything to be back as he never oppened it?
 
The SaveOnClose you mention is the saving of any design changes to the form and not data written to the table.
Data is saved to the underlying table as soon as a character is typed in the the first field.
You could try having a 'Cancel' button on the form and putting Me.Undo in the OnClick Event. This should cancel all changes made to the current record.
Or a more comlexed way is to use an unbound form with unbound text boxes and then use code to append the record to the table.

HTH
 
What about the Esc key? Is there a way to "simulate" with a macro what the Esc key does before closing the form? It's more or less what I want my form to do.
 
I don't know if this helps you, but here is the code that I have on an Undo Record button.
--------------------------------------
Private Sub btnUndoRecord_Click()
On Error GoTo Err_btnUndoRecord_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

Exit_btnUndoRecord_Click:
Exit Sub

Err_btnUndoRecord_Click:
MsgBox Err.Description
Resume Exit_btnUndoRecord_Click

End Sub
------------------------------------------
This was generated by the button wizard, by the way, so you may like to use that.

Regards,
Brendan
 
I added the procedure you described to the "close without saving button". This works perfectly when the user has started adding or changing the contents. However, if no changes or aditions have been made and the user clicks on the button to exit the form, he gets an error message "you can't undo" or something like that and the procedure stops there (the form doesn't close). Any idea on how to deal with that?
 
Why not split the tasks? Rather than have a close without saving option, create one button to undo any data entry (using the code above) and another to close the form.

BON
 
You could maybe check the primary key field like UserID or something on your form and see if it is null. If it is then close if it isn't then me.undo.

kim
 
You may simulate the Esc key using Sendkeys "{Esc} {Esc}" under VBA; Not as elegant as undo but it I already found it helpfull under certain circumstances. Be sure to check whether the Sendkeys bug was fixed under the version of acesse you are using (it would unlock the Numlock Key otherwise).
 
Here's a different suggestion to avoid this problem:
1.)Create duplicate textboxes for each bound textbox(or whatever sort of control you may be using) on your form by copying & pasting all the textboxes you currently have on your form.
2.)Set the duplicate textboxes controlsource to "unbound" so they have no effect on the data in your table. Also it's a good idea to name them after the control the were copied from(Name>>Duplicate_Name, Address>>Duplicate_Address, or whatever naming convention your used to.)
3.)Make the textboxes that are bound to the table invisible to the user by setting the visible property to false. (Now the user can only see the unbound, duplicate textboxes on the form. The user can enter and remove data into the these textboxes without changing the data in the table.)
4.)Create an "Apply" button on your form that the user can click when he/she wants to update the table. For the OnClick event for the "Apply" button, write a procedure that goes to new record on the form(DoCmd.GoToRecord , , acNewRec or set the forms DataEntry property to "yes") and then moves the data from the unbound textboxes to the bound textboxes(i.e. Me!Name = Me!Duplicate_Name, Me!Address = Me!Duplicate_Address and so on). By doing so the user will have updated the table only after they click the "Apply" button. Now the user can enter any data onto the form without automatically updating the table that the form is based on. The "Apply" button now takes care of updating the table when the user is done entering data, but if he/she wants to exit the form after they've started adding data to the textboxes, the table will remain unchanged.
I hope this helps.
 

Users who are viewing this thread

Back
Top Bottom