Save data only when button is clicked

  • Thread starter avtuvy via AccessMonster.com
  • Start date
A

avtuvy via AccessMonster.com

I cretaed a form which is bound to a table and includes a "save" button which
calls acCmdSaveRecord. With the way it is now if I change any information in
the form the data is saved immedietly into the table. I would like to change
it so only when the "save" button is clicked data will be saved. Is there an
easy way to do that or it needds to be done with VBA?
 
A

Allen Browne

The *only* way to catch the save is to use the BeforeUpdate event of the
form. Access fires that event regardless of what triggers the save.

In general, this is bad technique. Whatever it is you need to do
(validation?), just move it into Form_BeforeUpdate, and let the user save
the record however they wish.

If you must do it, here's how:
1. Declare a boolean variable in the General Declarations section (top) of
the form's module:
Private bAllowSave As Boolean

2. Set up the form's BeforeUpdate event procedure to cancel the save unless
the button was clicked:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If bAllowSave Then
bAllowSave = False
'put your validation code here.
Else
Cancel = True
MsgBox "Click the button, dummy!"
End If
End Sub

3. Set up the Click event procedure of your button like this:
Private Sub Command1_Click()
bAllowSave = True
Me.Dirty = False
bAllowSave = False
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top