How do I stop Access from saving a record before I want it to?

G

Guest

Hi,

I hope someone can help me with this. I have a form that has your standard
Add, Edit, Delete, Save and Exit buttons. When the user adds a record, he or
she must select the Save button to actually save the record, because there is
a complicated process behind the scenes that must be run. I put in a safety
measure that, if the user selected Exit before the Save, the user would get a
prompt that would as them if they wanted to exit without saving their new
record. If so, then the program performs the undo command and all is well.
If the user selects no, I want to save this record, I would just return them
to the screen. But it seems that Access actually saves the record at this
point and then when my program goes to check for duplicate data etc., of
course it produces and error as such, because the record was already saved.

What can I do to stop this? I am currently using the Click event
procedures. Thanks so much for any help you can give me.
 
R

RuralGuy

Hi,

I hope someone can help me with this. I have a form that has your standard
Add, Edit, Delete, Save and Exit buttons. When the user adds a record, he or
she must select the Save button to actually save the record, because there is
a complicated process behind the scenes that must be run. I put in a safety
measure that, if the user selected Exit before the Save, the user would get a
prompt that would as them if they wanted to exit without saving their new
record. If so, then the program performs the undo command and all is well.
If the user selects no, I want to save this record, I would just return them
to the screen. But it seems that Access actually saves the record at this
point and then when my program goes to check for duplicate data etc., of
course it produces and error as such, because the record was already saved.

What can I do to stop this? I am currently using the Click event
procedures. Thanks so much for any help you can give me.

Put your stop save code in the BeforeUpdate event of the form. Set Cancel =
True and Me.UnDo if you don't want to save but exit anyway.
_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
G

Guest

Thanks for responding to my question, but I am missing something. How do I
enter the cancel command. The Set Cancel = True gives me an error. It
says object required.

Kathy
 
R

Rick Brandt

KmhComputer said:
Thanks for responding to my question, but I am missing something.
How do I enter the cancel command. The Set Cancel = True gives me
an error. It says object required.

Lose the "Set". Just plain old...

Cancel = True
 
G

Guest

Thanks, I actually just tried that and it worked. But, how do I keep it from
actually closing my form. If the user wants to exit without saving,
everything is fine, but when I use the cancel, it 's not saving the record,
but it is also closing my form. I don't want it closed. So how do I stop
that from happening?
 
R

Rick Brandt

KmhComputer said:
Thanks, I actually just tried that and it worked. But, how do I keep
it from actually closing my form. If the user wants to exit without
saving, everything is fine, but when I use the cancel, it 's not
saving the record, but it is also closing my form. I don't want it
closed. So how do I stop that from happening?

The Close even also has a Cancel argument.
 
R

RuralGuy

Thanks, I actually just tried that and it worked. But, how do I keep it from
actually closing my form. If the user wants to exit without saving,
everything is fine, but when I use the cancel, it 's not saving the record,
but it is also closing my form. I don't want it closed. So how do I stop
that from happening?

Dim a public variable and test in in the UnLoad event of the form.
Cancel = True until you want to let the user out of the form.
_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
R

RuralGuy

The Close even also has a Cancel argument.

Sorry Rick,
I don't think the Close event can be cancelled but the UnLoad event can.
_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
G

Guest

Thanks so much guys for all your help, I've gotten it to work!
Now on with the rest of the application testing.....
 

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