Save reord from a form

A

Ac

Hi,

I have a form which user can use it to update the table and there is a
button on it named Save. I would like user to click on Save button to save
the record; otherwise, the input data will not be added into the table after
the form closed. How can I write the code? Thanks!
 
A

Allen Browne

Ac said:
I have a form which user can use it to update the table and there is a
button on it named Save. I would like user to click on Save button to save
the record; otherwise, the input data will not be added into the table
after
the form closed. How can I write the code? Thanks!

Many, many things can trigger the saving of the record other than your Save
button, e.g. Shift+Enter, Save on Records, menu, closing the form, closing
Access, applying a filter, changing the sort order, navigating to another
record, tabbing past the last control, and so on.

You must learn to work with the built-in events. Access fires the
BeforeUpdate event of the form just before the record is saved. If you need
to test anything, use Form_BeforeUpdate to do that. If you need to block the
save, cancel the event.

If it is absolutely essential that the save happens only through your
button, create a module-level boolean variable in the General Declaraions:
Dim mbAllowSave As Boolean

In your button's code:
If Me.Dirty Then
mbAllowSave = True
Me.Dirty = False
mbAllowSave = False
End If

In Form_BeforeUpdate:
If Not mbAllowSave Then
Cancel = True
MsgBox "You didn't click my Save button!"
End If
mbAllowSave = False

But I wouldn't buy your app if you did that. :)
 
A

Ac

Hi Allen,

The purpose to write this code is if the user did not finish the data
entering for the whole form then closed the form, the user wanted to close
the form without saving the record. Actually, when the form closed, the
record automatically saved on table. I try to stop this confusing, make sure
the record saved only on the Save button is clicked. Thanks.
 

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