auto saving ?

carbo20

Registered User.
Local time
Yesterday, 19:41
Joined
Mar 18, 2004
Messages
15
hello i have a problrm with a from .
when i start entering data it auto save it.
i added this code : (i found it here)

Private Sub Command23_Click()

If MsgBox("do you want to save?", vbOKCancel, "save event") = vbOK Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Else
Me.Undo
End If
end sub

but it got no meaning bcoz access saves the data anyway.
how can i save only if the user press the ok botton?

Thank you.
 
Use the Before Update event of the form to display the message box and not a button
 
Just as Rich suggested...
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Form_BeforeUpdate_Err
    
    If MsgBox("The current record has been altered.  Do you wish to save your changes?  Click 'Yes' to Save or 'No' to Discard the changes.", vbQuestion + vbYesNo, "Save Current Record Change?") = vbYes Then
        'User clicked Yes, do nothing
    Else
        DoCmd.RunCommand acCmdUndo
    End If
    
Form_BeforeUpdate_Exit:
    Exit Sub
    
Form_BeforeUpdate_Err:
    MsgBox Err.Number & " " & Err.Description
    Resume Form_BeforeUpdate_Exit
    
End Sub
 

Users who are viewing this thread

Back
Top Bottom