Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to save only when Save button is clicked

Status
Not open for further replies.

Swiftraven

Technical User
Oct 29, 2001
28
US
Hi,
I have a form that is tied to a table. What I need is that for any data that the user changes on the form, it will only be saved to the table if they click the Save button. If they close the form/go to next record/go to a different form, I need for the data to not be updated in the table.
The form consists of text boxes and combo boxes.

Thanks in advance,
Jason
 
Hi Jason!

I'm not sure if this will work:

First, In the general declarations:

Private bolSave As Boolean

Private Sub Form_Current()
bolSave = False

Private Sub Form_BeforeUpdate(Cancel As Integer)
If bolSave = False Then
Me.Undo
Cancel = -1
End If
End Sub

Private Sub cmdSave_Click
bolSabe = True
DoCmd.RunCommand acCmdRecordsGoToNew
End Sub

You will probably need to add error messages and tips for the user.

Alternatively, you could make the form unbound and use an action query to save the information when the save button is pushed. In that case you also need to put in warnings to let the user know when they are saving and when they are not.

hth
Jeff Bridgham
bridgham@purdue.edu
 
I have not tested it but i think you can use the Oldvalue property of the controls on the form in the Beforeupdate event of the form to reset the original values and save the values in the OnClick event of the button using code

Sub Form_Beforeupdate()
Me!Control1=Me!Control1.Oldvalue
Me!Control2=Me!Control2.Oldvalue
.
.

End Sub



 
Or for a quick solution...
Create a Checkbox and make it not visible and DefaultValue Property to true. Then:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me![Checkbox1] Then
Me![Control1] = Me![Control1].OldValue
Me![Control2] = Me![Control2].OldValue 'etc

End If
End Sub

Private Sub Button1_Click()

Me![Checkbox1] = False
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70 'This comes from wizard
Me![Checkbox1] = True

End Sub

Quick and dirty...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top