Messages at form closing?

G

Guest

Hi all,

I've a form with some subforms. One one of the subforms is a command button
that updates the subform table record. This all works fine, however, when I
"X" to close the subform, I get the two-headed message monster of:

" The changes you requested to the table were not successful because they
would create duplicate calues in the index, primary key, or relationship.
Change the data in the field or fields that contain the duplicate data,
remove the index, or redefine the index to permit duplicate entries and try
again."

and:

"You can't save this record at this time. Do you want to close the database
object anyway?"

So, it seems the default of the "X" button is to update the table by
creating a new record? Is there any way around this behavior or messages? I
tried putting "DoCmd.SetWarnings False" in the BeforeUpdate event of the
subform, but that didn't help.

Thanks,
Rodi
 
A

Allen Browne

Yes, the default in Access is to save the record when you close the form,
move to a different record, filter the form, sort the form, and so on.

And it's a *really* good idea that Access notifies you if your entry was not
saved. Personally, if I found that I had bought a piece of software that
sometimes just silently lost whatever I entered with no notification at all,
I would refuse to use the software and ask for my money back.

It is possible to suppress those messages using a combination of the Error
event of the form and the BeforeUpdate event of the form. But are you sure
you want to just throw away people's entry and leave them with the belief
that "I entered it, but your program loses it!"
 
G

Guest

Hey Allen,

Thanks for your response.

I get what mean about notification, but at that point, the record's already
been saved. The genesis of all this is that I couldn't use a "normal" Add or
Save command buttong, so I coded my own that updates to the degree I
specified, and that works fine. But, when I tried to use the "X", I got the
messages I specified.

What I did was include a clos form command in the command button, which dos
work, but I'd appreciate any other thoughts you have on this.

Thanks
 
T

Tim Ferguson

So, it seems the default of the "X" button is to update the table by
creating a new record? Is there any way around this behavior or
messages? I tried putting "DoCmd.SetWarnings False" in the
BeforeUpdate event of the subform, but that didn't help.

Use the BeforeUpdate event actually to vaidate the data and help the user
through whatever he or she needs to do to amend the situation. This might
be to abandon the record he or she has spent the last fifteen minutes
typing in, or overwriting the old one, or changing the PK values on the
new one so that both records can live in harmony together, or whatever...

Even better, how about managing the record creation stage, so that the
user is never faced with a post-hoc key violation? What about getting him
or her to pick an existing record, or error check the new PK value as
soon as it's entered, etc? This is called work flow management, and it
should be part of the systems analysis you did before starting to code
your database.

Best wishes


Tim F
 
A

Allen Browne

Ah. So you were using the really nasty bug where Access does silently lose
the user's entry. We have that documented as the #1 flaw in Access here:
http://allenbrowne.com/bug-01.html

The real solution will involve using the Form_BeforeUpdate and Form_Error
events to handle the problems, and give the users a suitable notification
(custom messages if you wish.)

Who is this software for? I have yet to find anyone who complained about
these messages who--when it was explained to them--would prefer to have
Access just silently lose their data.
 

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