A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Save data only when button is clicked



 
 
Thread Tools Display Modes
  #1  
Old March 29th, 2010, 02:08 PM posted to microsoft.public.access.forms
avtuvy via AccessMonster.com
external usenet poster
 
Posts: 3
Default Save data only when button is clicked

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?

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201003/1

  #2  
Old March 29th, 2010, 04:08 PM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default Save data only when button is clicked

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

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"avtuvy via AccessMonster.com" u58699@uwe wrote in message
news:a5bbb2f0f7a8d@uwe...
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?

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201003/1

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:19 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.