Undo Record Problem

N

Natalie

I have a form that inputs data into a table. I have 3 click buttons. One Adds
the Record to the table (Goes to next record), another Clears the form(Undo
the Record) and I have a third that closes the form. If there is no test
entered, form closes. If there is text typed, and then form is closed, the
text still gets added to the table. Solution to stop that, I had the
Close_Click() Undo the Record and then close the form. But now, if I add a
record and then close the form, I get a message asking me if I'm sure I want
to delete the record since that's what the Undo Record would do. I can click
no, so it won't delete the record, but I want to prevent this message from
coming up at all. Any suggestions?
 
T

tina

well, how shall Access know when the user wants the current record to be
added, and when it should be discarded, on form Close? you said your "Add
the Record" button simply moves to the next record. so apparently you want
to be able to save a record when the form closes, without clicking the "Add"
button first?

you need to get a clear picture in your mind of how you want the form to
behave, how you want the user to behave, and what should happen if/when the
user doesn't behave as expected. whenever possible (though sometimes it is
*not* possible), it's better to limit your users to choices that will lead
to specific desired outcomes.

you might try disabling the Close button when the form's Dirty property is
True, and enabling it when the Dirty property = False. that way, once the
user dirties the current record, by typing something in a control, s/he must
either Add the record, or Clear the form, before the Close button becomes
available.

hth
 
D

David Cox

Natalie, what has this got to do with table design? There is using
newsgroups and abusing newsgroups, you have already asked this question
elsewhere.
 
N

Natalie

Sorry about the multipost. I'm new to this forum and didn't realize there was
a section for programming until after I had already placed this post. I
didn't know reposting was such a bad thing. It wasn't intentional and won't
happen again.
 
T

tina

fair enough. :)


Natalie said:
Sorry about the multipost. I'm new to this forum and didn't realize there was
a section for programming until after I had already placed this post. I
didn't know reposting was such a bad thing. It wasn't intentional and won't
happen again.
 
T

tina

well, try something like this: in the form's Dirty event procedure, add
code as

Me!cmdClose.Enabled = False

so when the form is dirtied (data is entered/edited), the Close button is
disabled. now the use has only two choices: click the Add button to save
the data, or click the Clear button to undo the changes.

in the Add button's Click event procedure, after the code you already have
there, add another line of code, as

Me!cmdClose.Enabled = Not Me.Dirty

also add the above code to the Clear button's Click event procedure, again,
after the code you already have there. now after the code runs on the
clicked button, Access will check to see if the form is Dirty. if it is, the
Close button stays disabled; if it is not Dirty, the Close button becomes
enabled and the user can close the form.

hth
 

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