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!

Cancelling the Save Event Procedure

Status
Not open for further replies.

topazny

IS-IT--Management
Apr 26, 2002
3
GB
Hi folks,

Does anyone know whether it is possible to prevent Access from saving the data in a form automatically, when the user either:

(a) presses the "X" button on the top right of the screen;
(b) presses the "new record" button I have on my form
(c) loses focus on the main form, while moving to the subform

Ideally, I'd like Access to save the record, only when the user presses a save button that I create on the form, and at no other time.

Can anyone help?

I'm pretty new to this Access lark, so basic instructions would be appreciated ;0)
 
I think you have to use unbound fields. In the Save button event you save each field.

dim dbs as Database
set dbs = CurrentDb

Dim rst as Recordset
Set rst = dbs.OpenRecordset("tablename", dbOpenDynaset)

rst.AddNew
rst!field1 = data
rst!field2 = data
...

rst.Update

rst.Close
dbs.Close

Unbound fields won't be saved when you press the close button. They will only be saved when you run the procedure to save each field.

Albert
 
One of ways how to solve your problem is Boolean type variable using. You can confirm this variable value on update.

Dim blnSave As Boolean

Private Sub cmdSave_Click() 'Sub program of <Save button>
blnSave = True
DoCmd.RunCommand acCmdSaveRecord
blnSave = False
End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)
'You can also put here message box, which informs user
'that he needs to save record by pushing <Save button> before next operation

Cancel = Not blnSave
End Sub

Aivars [pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top