Stop save when close or new button (1 Viewer)

MAAS8000

Registered User.
Local time
Today, 03:03
Joined
Apr 3, 2018
Messages
38
access by default save all records immediately
In the entry form the access save the entry always on closing or pressing new,
I need saving to be after pressing save only
 

MarkK

bit cruncher
Local time
Today, 03:03
Joined
Mar 17, 2004
Messages
8,178
Why? It's harder. Why do it the harder way? If you don't want the record, just delete it. Also, you can undo the creation of a new record if you hit ctrl + z.
hth
Mark
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:03
Joined
May 7, 2009
Messages
19,175
There is a thread similar of what you have. The solution is transated form. Go and search for it.
 

MAAS8000

Registered User.
Local time
Today, 03:03
Joined
Apr 3, 2018
Messages
38
There is a thread similar of what you have. The solution is transated form. Go and search for it.
if you could help me , I will be thankful.
I have two problem in the previous, and after search I solved one but this NO
thank you:):)

the problem in other words, I don't want access to save record from the entry form until the user press save. to avoid unintended saving when close or new.
 

bob fitz

AWF VIP
Local time
Today, 10:03
Joined
May 23, 2011
Messages
4,717
if you could help me , I will be thankful.
I have two problem in the previous, and after search I solved one but this NO
thank you:):)

the problem in other words, I don't want access to save record from the entry form until the user press save. to avoid unintended saving when close or new.
you could use the form's Before Update event to catch attempt to save the record and then cancel the update if the record should not be saved.
 

MAAS8000

Registered User.
Local time
Today, 03:03
Joined
Apr 3, 2018
Messages
38
I have tried this but not working in the close button . it also make saving

Private Sub Command12_Click()
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub
 

bob fitz

AWF VIP
Local time
Today, 10:03
Joined
May 23, 2011
Messages
4,717
As I said in my previous post, you need code in the form's Before Update event which would cancel the update if validation fails
 
Last edited:

missinglinq

AWF VIP
Local time
Today, 06:03
Joined
Jun 20, 2003
Messages
6,423
Here's some boilerplate code I ran up years ago, using the approach already suggested, here:

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

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 New Record ???") = vbNo Then
   Me.Undo
  End If
End If

End Sub
Linq ;0)>
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:03
Joined
Feb 19, 2002
Messages
42,981
DoCmd.Close acForm, Me.Name, acSaveNo
That has nothing to do with preventing a record from being saved. It is saying don't save any design changes to the form. ALL control over whether or not to save a record revolves around the form's BeforeUpdate event.

If you must do this, you will need to create a public variable that you set and check in several places.

Dim the variable before the first procedure in the form's class module. Make it a Variant so you can set it to Null.

Public vSave As Variant

Then:

1. Set the variable to Null in the form's Current Event
2. Set the variable to "Save" in the click event of your save button.
3. Set the variable to Null in the AfterUpdate event of the Form
4. Set the variable to "NoSave" in the click event of the close button.
5. In the BeforeUpdate event of the form check the variable.
Code:
If vSave = "Save" Then
Else
    If IsNull(vSave) then
        If MsgBox("You have made changes but not pressed Save or Cancel.  Do you want to Save?", vbYesNo) = vbNo Then
            Cancel = True
            Me.Undo
            Exit Sub
        End If
    Else
        Cancel = True
        Me.Undo
    End If
End If
 

Users who are viewing this thread

Top Bottom