Saving edits in form only when save button is used

gcomp

Registered User.
Local time
Yesterday, 22:39
Joined
May 28, 2010
Messages
45
I have an inventory database that tracks all of our parts. I have set up an "Edit Inventory" form so that users can update pricing, vendor, etc. The problem is that they sometimes inadvertently change another field without knowing it.

Is there a way to set up the "Save" button to only save changes when clicked? Or ask if they want to save when exiting the form if they haven't clicked "Save"?
 
In the Form_BeforeUpdate event you could put the line:

Code:
    If Me.Dirty Then If MsgBox("Save Changes?", vbYesNo) = vbNo Then Me.Undo

There are definitely people here who would advise you not to go down the save button route and with good reason.
 
Thanks for the reply, but I keep getting a compile error. Here is what I have for the before update event:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Dirty Then If MsgBox("Save Changes?", vbYesNo) = vbNo Then Me.Undo

End Sub
 
That looks fine to me and I've tested it and it works. I don't think it needs any unusual references.

Maybe trying expanding out the single-line If:

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Dirty Then 
    If MsgBox("Save Changes?", vbYesNo) = vbNo Then 
        Me.Undo
    End If
End If
End Sub
 
Still get the compile error, expected identifier
 
1st line: Private Sub Form_BeforeUpdate(Cancel As Integer)
 
I fixed the issue. I had another program being called too. Your code was OK. It works like a wonder! Thanks!
 
There is no need to check the Me.Dirty flag. It will be true 100% of the time. That's why the BeforeUpdate event fired - the record was dirty and needed to be saved.

If they are accidentally changing lookup data, lock the controls. They shouldn't be changing the description, for example, if they are loging receipts.
 

Users who are viewing this thread

Back
Top Bottom