How to prevent changes save to recordset and table

  • Thread starter Thread starter Ben
  • Start date Start date
B

Ben

Hi all,

I have the following code with a recordset tied to a form:

Set rsEditCient = New ADODB.Recordset
rsEditCient.CursorLocation = adUseClient
rsEditCient.Open strSQL, cnndb, adOpenStatic, adLockBatchOptimistic, adCmdText

DoCmd.OpenForm "frm_Edit_Client"
Set Forms("frm_Edit_Client").Recordset = rsEditCient

There are two buttons. One for update for when I make any update changes.
The other is a back button that would bring me to a previous form. However,
if I make any changes and click the back button or simply X out of the form,
it saves those changes too, which is not the intention, since I have an
update button for that purpose.

Can you tell me what I need to do to prevent the changes from being saved to
the recordset and subsequently back to the table, if I just click the back
button or X out of the form?

Thanks so much for your help,

Ben


--
 
Hi Ben,


Try looking at transactional wrappers....

so open the transaction

make the changes to your dataset

then if you bin the changes call the Rollback function

or if you're happy - call the "Commit"

simplistic example below
================
Dim conn as adodb.connection
On Error goto Err_Trap

set conn = new adodb.connection
conn.open "ConnectionStringHere"
conn.BeginTrans

conn.Execute "SQL_STRING"

conn.CommitTrans
Conn.Close
Exit Sub

Err_Trap:
conn.RollbackTrans

======================
 
I would simply do it this way.

Add a hidden checkbox to the form. In the OnCurrent event for the form, make
sure you set the checkbox to False.

When the user clicks Update, set the field to True before you issue the save
commands for the form.

In the form's BeforeUpdate event, check to see if the checkbox is true or
false. If it is false, you can Cancel the update. If the user hits Back
without ever hitting Update, the data will not be saved.

If you want the ability for the user to hit Update and then undo the update
if the user click's back, then Rob's way is better.

RJ
Database Whiz Consulting
www.databasewhiz.com
 
I sent this yesterday but it doesn't appear to have posted...


I would simply do it this way.

Add a hidden checkbox to the form. In the OnCurrent event for the form, make
sure you set the checkbox to False.

When the user clicks Update, set the field to True before you issue the save
commands for the form.

In the form's BeforeUpdate event, check to see if the checkbox is true or
false. If it is false, you can Cancel the update. If the user hits Back
without ever hitting Update, the data will not be saved.

If you want the ability for the user to hit Update and then undo the update
if the user click's back, then Rob's way is better.

RJ
Database Whiz Consulting
www.databasewhiz.com
 
Back
Top