Escape button --> code?

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

Guest

On a form I have textboxes linked to a query (giving one record). Clicking a
button, I go to the emty record. Filling this in I create a new record.

When I push a button <cancel>, all has to be as before. I work this way: I
go to the first record to delete possible changes (overwrite with originals)
DoCmd.GoToRecord , , acFirst
Then: put old values back in cells (values stored in labels when opening
form).

PROBLEM:
when enterring values in empty record fields, a new record is made.
Cancelling has to undo this. Now the first record is set to original and a
record has been made if somebody filled it in.

QUESTION:
Filling in the empty record, I can go back to initial values using the
"ESCAPE" button. How can I program this so I can implement it in my
Cancel-button-code?
 
Zurn said:
On a form I have textboxes linked to a query (giving one record). Clicking a
button, I go to the emty record. Filling this in I create a new record.

When I push a button <cancel>, all has to be as before. I work this way: I
go to the first record to delete possible changes (overwrite with originals)
DoCmd.GoToRecord , , acFirst
Then: put old values back in cells (values stored in labels when opening
form).

PROBLEM:
when enterring values in empty record fields, a new record is made.
Cancelling has to undo this. Now the first record is set to original and a
record has been made if somebody filled it in.

QUESTION:
Filling in the empty record, I can go back to initial values using the
"ESCAPE" button. How can I program this so I can implement it in my
Cancel-button-code?


Use the form's Undo method:
Me.Undo

When you move to the first record, the new record was saved
automatically. Once a record has been saved, Undo can not
reset the values, so I am concerned about your use of
DoCmd.GoToRecord , , acFirst
This should **not** be used to manage the appearance of the
screen or to save a record.
 
Marshall Barton said:
Use the form's Undo method:
Me.Undo

When you move to the first record, the new record was saved
automatically. Once a record has been saved, Undo can not
reset the values, so I am concerned about your use of
DoCmd.GoToRecord , , acFirst
This should **not** be used to manage the appearance of the
screen or to save a record.

"DoCmd.GoToRecord , , acFirst
This should **not** be used to manage the appearance of the screen or to
save a record."

Maybe I explained wrong. To go to the second (empty) record in the query, I
use DoCmd.GoToRecord , , adNew. I think that adding a record with this method
is allowed. It's only when I make a mistake and want to go back to original
settings that I use the DoCmd.GoToRecord , , acFirst because I have to rework
the values in the textboxes. With .OldValue, it works only if you have
corrected the textboxes only once.

Thank you for your help.
 
Zurn said:
"DoCmd.GoToRecord , , acFirst
This should **not** be used to manage the appearance of the screen or to
save a record."

Maybe I explained wrong. To go to the second (empty) record in the query, I
use DoCmd.GoToRecord , , adNew. I think that adding a record with this method
is allowed. It's only when I make a mistake and want to go back to original
settings that I use the DoCmd.GoToRecord , , acFirst because I have to rework
the values in the textboxes. With .OldValue, it works only if you have
corrected the textboxes only once.


OK, I was concerned about that, but it seems that you were
doing it correctly.

The OldValue property represents the value of the fields
(bound to the text box control) when the record was saved.
Since navigating to a different record automatically saves a
record, you can not use OldValue to reset values after
moving to a new record and moving back to the first record.

I'm not sure if I answered your question or if you need
additional help.
 
Marshall Barton said:
OK, I was concerned about that, but it seems that you were
doing it correctly.

The OldValue property represents the value of the fields
(bound to the text box control) when the record was saved.
Since navigating to a different record automatically saves a
record, you can not use OldValue to reset values after
moving to a new record and moving back to the first record.

I'm not sure if I answered your question or if you need
additional help.
Thank you for helping me out on this!
Greets,
Zurn
 
Back
Top