Records always saved

S

Simon Harris

Hi All,

I have two buttons on a form...


Button A is for exit and save. Onclick event does the following:
---------------------------------------------------------------
Private Sub AddAmendOrderSaveButton_Click()
On Error GoTo Err_AddAmendOrderSaveButton_Click
'Save the record, requery the customers view form, so our new record is
displayed
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Forms![FRM_switchboard]![SUBFRM_view_orders].Requery
'Switch off Echo method to avoid seeing 'enter parameter value' box
(See MS KB Article 811860)
DoCmd.Echo False
DoCmd.Close acForm, "FRM_add_amend_order"
'Switch echo back on
DoCmd.Echo True
Exit_AddAmendOrderSaveButton_Click:
Exit Sub
Err_AddAmendOrderSaveButton_Click:
MsgBox Err.Description
Resume Exit_AddAmendOrderSaveButton_Click
End Sub


Button B is for exit with *no* save. Onclick event does the following
---------------------------------------------------------------------
Private Sub AddAmendOrderCloseButton_Click()
'User has clicked exit button, so close the form
ReturnValue = MsgBox("Are you sure you want to close with out saving?",
vbDefaultButton2 + vbQuestion + vbOKCancel, "Close job without saving - Are
you sure?")
Select Case ReturnValue
Case vbOK
'Switch off Echo method to avoid seeing 'enter parameter value' box
(See MS KB Article 811860)
DoCmd.Echo False
DoCmd.Close acForm, "FRM_add_amend_order"
'Switch echo back on
DoCmd.Echo True
Case vbCancel
End Select
End Sub


Changes made are always saved, whether button A or B are pressed. I suspect
this is something to do with the way I have opened the record, which is like
this:

Private Sub SUBFRM_view_customers_DblClick(Cancel As Integer)
'User double clicked the customers list
stDocName = "FRM_add_amend_customer"
stLinkCriteria = "[id]=" & Forms!FRM_switchboard!SUBFRM_view_customers
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub

Can anyone advise, or point me in the right direction to how I go about
making a button, or changing my form so that the user can exit without
saving changes?

Kind regards,

Simon.



--
-
* Please reply to group for the benefit of all
* Found the answer to your own question? Post it!
* Get a useful reply to one of your posts?...post an answer to another one
* Search first, post later : http://www.google.co.uk/groups
* Want my email address? Ask me in a post...Cos2MuchSpamMakesUFat!
 
D

Douglas J. Steele

Assuming you've got a bound form, Access is always going to save by default.
In other words, telling it to save in the first case wasn't really
necessary, and what you've got for the "No" answer doesn't do anything
because you don't actually tell Access to undo the changes.

See http://support.microsoft.com/?id=197103 for the easiest way to do what
you're trying to do.

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



Simon Harris said:
Hi All,

I have two buttons on a form...


Button A is for exit and save. Onclick event does the following:
---------------------------------------------------------------
Private Sub AddAmendOrderSaveButton_Click()
On Error GoTo Err_AddAmendOrderSaveButton_Click
'Save the record, requery the customers view form, so our new record is
displayed
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Forms![FRM_switchboard]![SUBFRM_view_orders].Requery
'Switch off Echo method to avoid seeing 'enter parameter value' box
(See MS KB Article 811860)
DoCmd.Echo False
DoCmd.Close acForm, "FRM_add_amend_order"
'Switch echo back on
DoCmd.Echo True
Exit_AddAmendOrderSaveButton_Click:
Exit Sub
Err_AddAmendOrderSaveButton_Click:
MsgBox Err.Description
Resume Exit_AddAmendOrderSaveButton_Click
End Sub


Button B is for exit with *no* save. Onclick event does the following
---------------------------------------------------------------------
Private Sub AddAmendOrderCloseButton_Click()
'User has clicked exit button, so close the form
ReturnValue = MsgBox("Are you sure you want to close with out saving?",
vbDefaultButton2 + vbQuestion + vbOKCancel, "Close job without saving - Are
you sure?")
Select Case ReturnValue
Case vbOK
'Switch off Echo method to avoid seeing 'enter parameter value' box
(See MS KB Article 811860)
DoCmd.Echo False
DoCmd.Close acForm, "FRM_add_amend_order"
'Switch echo back on
DoCmd.Echo True
Case vbCancel
End Select
End Sub


Changes made are always saved, whether button A or B are pressed. I suspect
this is something to do with the way I have opened the record, which is like
this:

Private Sub SUBFRM_view_customers_DblClick(Cancel As Integer)
'User double clicked the customers list
stDocName = "FRM_add_amend_customer"
stLinkCriteria = "[id]=" & Forms!FRM_switchboard!SUBFRM_view_customers
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub

Can anyone advise, or point me in the right direction to how I go about
making a button, or changing my form so that the user can exit without
saving changes?

Kind regards,

Simon.



--
-
* Please reply to group for the benefit of all
* Found the answer to your own question? Post it!
* Get a useful reply to one of your posts?...post an answer to another one
* Search first, post later : http://www.google.co.uk/groups
* Want my email address? Ask me in a post...Cos2MuchSpamMakesUFat!
 
S

Simon Harris

Thanks Douglas...Much appreciated.

Simon.

Douglas J. Steele said:
Assuming you've got a bound form, Access is always going to save by default.
In other words, telling it to save in the first case wasn't really
necessary, and what you've got for the "No" answer doesn't do anything
because you don't actually tell Access to undo the changes.

See http://support.microsoft.com/?id=197103 for the easiest way to do what
you're trying to do.

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



Simon Harris said:
Hi All,

I have two buttons on a form...


Button A is for exit and save. Onclick event does the following:
---------------------------------------------------------------
Private Sub AddAmendOrderSaveButton_Click()
On Error GoTo Err_AddAmendOrderSaveButton_Click
'Save the record, requery the customers view form, so our new record is
displayed
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Forms![FRM_switchboard]![SUBFRM_view_orders].Requery
'Switch off Echo method to avoid seeing 'enter parameter value' box
(See MS KB Article 811860)
DoCmd.Echo False
DoCmd.Close acForm, "FRM_add_amend_order"
'Switch echo back on
DoCmd.Echo True
Exit_AddAmendOrderSaveButton_Click:
Exit Sub
Err_AddAmendOrderSaveButton_Click:
MsgBox Err.Description
Resume Exit_AddAmendOrderSaveButton_Click
End Sub


Button B is for exit with *no* save. Onclick event does the following
---------------------------------------------------------------------
Private Sub AddAmendOrderCloseButton_Click()
'User has clicked exit button, so close the form
ReturnValue = MsgBox("Are you sure you want to close with out saving?",
vbDefaultButton2 + vbQuestion + vbOKCancel, "Close job without saving - Are
you sure?")
Select Case ReturnValue
Case vbOK
'Switch off Echo method to avoid seeing 'enter parameter value' box
(See MS KB Article 811860)
DoCmd.Echo False
DoCmd.Close acForm, "FRM_add_amend_order"
'Switch echo back on
DoCmd.Echo True
Case vbCancel
End Select
End Sub


Changes made are always saved, whether button A or B are pressed. I suspect
this is something to do with the way I have opened the record, which is like
this:

Private Sub SUBFRM_view_customers_DblClick(Cancel As Integer)
'User double clicked the customers list
stDocName = "FRM_add_amend_customer"
stLinkCriteria = "[id]=" & Forms!FRM_switchboard!SUBFRM_view_customers
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub

Can anyone advise, or point me in the right direction to how I go about
making a button, or changing my form so that the user can exit without
saving changes?

Kind regards,

Simon.



--
-
* Please reply to group for the benefit of all
* Found the answer to your own question? Post it!
* Get a useful reply to one of your posts?...post an answer to another one
* Search first, post later : http://www.google.co.uk/groups
* Want my email address? Ask me in a post...Cos2MuchSpamMakesUFat!
 
V

Van T. Dinh

For bound Form, Access will automatically save the Record if there are
things to be saved. If you don't want to save, you need to use

Me.Undo

Before you close the Form.

HTH
Van T. Dinh
MVP (Access)
 

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