Save button

M

mcnewsxp

i know this has been asked many times before and i have my long handed coded
way of doing this, but is there a quick way to not save data on a bound form
until a Save button is clicked?

tia,
mcnewsxp
 
A

Allen Browne

The only way to prevent the save is to cancel the BeforeUpate event of the
form.

But you do want to allow the save if your button was clicked. You therefore
need a module-level variable that you set to True in your button's click
event, so if it is true in the form's BeforeUpdate event you permit the
save.

1. In the General Declarations of the form's module (at the top, with the
Option statements):
Dim mbAllowSave As boolean

2. In Form_BeforeUpdate:

If mbAllowSave Then
'Allow the save, reset the variable.
mbAllowSave = False
Else
'Prevent the save.
Cancel = True
MsgBox "Click the Save button, stupid!"
End If

3. In the Click event procedure of your Save button:
If Me.Dirty Then
mbAllowSave = True
RunCommand acCmdSaveRecord
mbAllowSave = False
End If

Okay, now we have demonstrated that it can be done, don't ask me to buy your
software, because I hate being stuck in that kind of straightjacket that
slows everyone down and proves the developer did not understand how to use
the form's events.

You avoid the whole problem if you just moved any validation checks you need
to run into the Form_BeforeUpdate event, and any responses that you need to
make once the record has been saved into the Form_AfterUpdate event.
 

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

Similar Threads

know which control has focus when button is clicked 4
export to CSV 1
Saving a record 4
Form Command Buttons 4
what event is navigate? 6
data entry 4
Change position of acDialog form 9
cancel changes on subform 2

Top