New Record Saved, before I've asked to save (1 Viewer)

DH_FE

New member
Local time
Today, 17:28
Joined
Mar 1, 2019
Messages
5
I'm trying to create a form to add a new vehicle service record.
The user would select the relevant vehicle then enter the date of the service and the mileage of the vehicle (both are required fields).
There's then an 'Add Record' option button.


What i've found is, if all the required information is entered into the form - the database gets updated anyway, without pressing 'add record'. Which would mean, if the user wanted to cancel the entry (either by closing the form, or going back to a previous form) for any reason, the new record is still added.


What I want is a true "Add Record" option - so the database isn't updated until it's pressed by the user. Or at the very least a 'cancel' option that would both delete the information entered and move the user back to the previous form.


edit:
all my options are the basic once selected within Access, i've not written any specific sql
 
Last edited:

JHB

Have been here a while
Local time
Today, 18:28
Joined
Jun 17, 2012
Messages
7,732
Is the form a continuous form or a single form?
What is the form's records source, a query or a single table?
You can post your database with some sample data, (zip it) + the name of the form in which you've problem!
 

Minty

AWF VIP
Local time
Today, 17:28
Joined
Jul 26, 2013
Messages
10,368
By default Access saves a record as soon as you move off the form or to another record.
Programming your way around this is awkward, and mostly unnecessary .

The simplest way to prevent a record being saved is in the Forms before update event. This fires before the record is saved.

You could simply put code along the lines of

Code:
If VbNo  = MsgBox("Save Record Changes?",VbYesNo) Then
     Cancel = True
     me.undo
End iF

Into the before update event, however I will guarantee users will get annoyed with this if 99% of the time they have added the data correctly.
 

DH_FE

New member
Local time
Today, 17:28
Joined
Mar 1, 2019
Messages
5
Unfortunately my form contains sensitive information, so I can't quickly post an example. However I think I've found a solution, by modifying the 'on click' embedded macro for buttons.
For the 'add' button i've set it to;
CloseWindow
Object Type : Form
Object Name : Add New Service Form
Save : Yes


For the 'cancel' button i've used the Wizard - Record Operations > Undo Record, then i've gone into the embedded macro and added;
CloseWindow
Object Type : Forem
Object Name : Add New Service Form
Save : No
Then moved that to just below the RunMenuCommand.


So far, in my testing, this appears to do exactly what I need.

Apologies for posting when i was so near to working this out.
 

Minty

AWF VIP
Local time
Today, 17:28
Joined
Jul 26, 2013
Messages
10,368
Your save and cancel actions aren't doing what you think. It's saving changes to the Form design not the record. (Or not saving changes to the form design)
It will appear to work as you are closing the form, which will save the record by default.

As I said the only way to do properly is with a ton of code and an unbound form, or use the before update event.

The run menu command will cancel the record.
 

Users who are viewing this thread

Top Bottom