Deleting a record when closing - after an autonumber has been incremented

JamesWB

Registered User.
Local time
Today, 04:56
Joined
Jul 14, 2014
Messages
70
I have a form that I want to open on a new record (with an Autonumber-based ID string that is a calculated field) and this uses a hidden field in the form when it opens to spawn a new record, ready to be related to some additional items in a join table. The user selects those from a list box.

I want to add a "return to main menu without saving" button, but not matter what code I use, it obstinately continues to save the record.

For example, I used

Code:
DoCmd.Close acForm, "JobPlanfromCAFs", acSaveNo

on the command button - no effect.

I also tried this code on the form's BeforeUpdate method. No effect. The new record continues to exist.

Code:
If Not (Me.NewRecord) Then
 If MsgBox("Would You Like To Save The Changes To This Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save Changes to Record ???") = vbNo Then
  Me.Undo
 End If
Else
 If MsgBox("Would You Like To Save This New Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save This Record ???") = vbNo Then
  Me.Undo
 End If
End If

How do I achieve this please? I suppose I can 'query out' incomplete records at other places in the database, but it's annoying to not be able to return to the same JobID again if you don't save it.

Thanks for any help.
 
As to your "no-effect" code, you've fallen into the trap of assuming what the code does, and getting surprised when it doesn't.

The first place to look is the documentation. Check what gets saved or not with DoCmd.Close and the parameters.

Also check what Undo does- and how to stop saving a record in BeforeUpdate.
 

Users who are viewing this thread

Back
Top Bottom