best way to ensure saving changes

icemonster

Registered User.
Local time
Today, 05:50
Joined
Jan 30, 2010
Messages
502
hello. :D

what would be the best way to ensure that people save their information? like if they were working on a form with a tab, and they move out of that form in general a message box would pop out, do you want to save your changes? then sets focus to the save button.

also, if the press the no, is it more logical to just use the Me.undo? are there more functions than undo to not save the changes?
 
If they have started a record then it, if the form is bound, it will save automatically when they close the form or move to another record.

To validate you use the FORM'S BeforeUpdate event. You can cancel the update if you set

Cancel = True

and you can undo if you use

Cancel = True
Me.Undo

and if validation passes just let it go and it will update.
 
so basically, if they dont click the save command i made, it wont save? cause that's my dilemma on a project i made back then, the save function was really just a fancy button because even if they move to another form or record, it still saves.
 
You would have to intercept things in the form's BEFORE UPDATE event and cancel them if your button wasn't clicked. You could have a boolean flag on your form - create it in the General Declarations section of the VBA module for that form like this:
Code:
Dim blnSave As Boolean

Then in your Save Button's click event you can put:
Code:
blnSave = True

and in the form's Before Update event you can put:
Code:
If blnSave = False Then
   MsgBox("Do you want to save the data?  If so, click the Save button.", vbExclamation
Cancel = True
Else
   blnSave = False ' resets it for the next record since if it got here the save button was clicked
End If
 
cool. so the the general declaration i just type the Dim blnSave as boolean? no underlying code after it?
 
sorry. i get it, on the forms general declarations. sorry.
 
This may be a bit of "overkill"; I solved the required data entry issue by using an unbound form where the user is forced to enter data in a required field or the data won't be saved. When all the required data is entered, pressing the save button connects the form to the underlying database to save the data.
 
I just can't understand using unbound forms in this instance. For a form/subform maybe since one saves when moved between. But in a single form, just take advantage of Access doing the work for you. It will save automatically unless it fails validation (if you put validation in on the Before Update event). It is simple - really.
 
how do i make this a yes or no question? like when the msgbox appears it would give the user two choices, yes then sets focus on the save button and no, just undos the changes. or cancels it out.
 
I just this:

Code:
Function IsDirty() As Boolean
    
    With CodeContextObject
        If .Dirty Then
            DoCmd.RunCommand acCmdSaveRecord
        End If
    End With
End Function

Not only is useful for save records but at times when processing complicated forms do a save before proceeeding to the next step. Also useful on new record creation, a forced save before call a report.

Simon
 
Bob's method is best because it also alerts the user. Sometimes a user will alter a field without realizing it and would save the unintended change if there wasn't a trap to catch a dirty record before the user moves off the current record or closes the form.

I still use a version of my old A Better Mouse Trap? sample to prevent and help my users.
 
ok.

i have tried bobs thing really is very efficient, but i tried the vbyes and vbno but i have a problem with itnergrating it, because what if the user does nto want to save it? how do i put a stop to the code?
 

Users who are viewing this thread

Back
Top Bottom