Undo Record Problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
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
 
Natalie, what has this got to do with table design? There is using
newsgroups and abusing newsgroups, you have already asked this question
elsewhere.
 
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.
 
I've read your post and understand exactly what you're saying. the only thing
is, I'm new to access and don't really know how to do what you're telling me.
Where do you see the "dirty" property? I'm guessing I'm going to use an If
Else statement for the Close form button. Where if form Dirty= False then
close form and when form dirty = true, undo record and then close form. How
would the syntax be to do that? Right now, this is how my close button code
looks:

Public Sub Close_Form_Click()
On Error GoTo Err_Close_Form_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
DoCmd.Close

Exit_Close_Form_Click:
Exit Sub

Err_Close_Form_Click:
DoCmd.Close
Resume Exit_Close_Form_Click

End Sub
 
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.
 
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
 
Back
Top