Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access DB - Changes are being saved instead of being canceled.

Status
Not open for further replies.

BraveDave

Programmer
Jun 16, 2005
9
0
0
US
Hey guys,
My app is using an Access DB with an ADODC control and some text boxes that connect to the DB and through them I can see the data and modify it.
I also use the KeyPreview=True in 'Form_Load', in order to use the F keys to do some functions and to move through the entries in the DB.
The thing is, when I'm using the F3 key, for-instance, to cancel the changes that were made to the DB by the Text Boxes using the command -
<<--CODE->>
AdoDB.Recordset.CancelUpdate 'To cancel the Changes made through the TxtBoxes
AdoDB.Recordset.AbsolutePosition=AdoDB.RecordSet.AbsolutePosition 'To Refresh the Textboxes.
<<-END OF CODE->>

The change is saved to the DB itself, instead of being canceled. When I run the cancel command by clicking the 'Cancel Changes' button with the mouse everything is fine.
I also did a little research and found out that the Recordset will only save the changes to the DB if I run the command by keyboard, as I've said, AND only if the cancel command is being run from 'Form_KeyUp' or 'Form_KeyDown'. If I run the cancel command with the keyboard through the 'Form_KeyPress' everything is alright. I would have use the 'Form_KeyPress' procedure, but I can't use the F Keys with it.
Do you have any Ideas of how to cancel the changes through the 'Form_KeyUp' or 'Form_KeyDown' procedures, or how to use the F keys through the 'Form_KeyPress' procedure?
Thank you very very much,
Dave.
 
It sounds like there might be something else going on. First, you can't trap the f keys through keypress event, that only handles keys with ascii values. Second, if you want to trap the F keys, you're doing it the right way. It sounds like there's something that's causing you to move off the record before you run the code, which would automatically post the changes.

I'd suggest that you do some more research evaluating when the adodc's beforeupdate event is fired, in relation to your keyup event.

HTH

Bob
 
Well, I have checked further more and got to this conclusion -
if I try to do some action on the DB, while the TextBox is focused the changes that were made will be saved to the DB.
I tried it by setting a timer for 1 second that will lunch the .CancelUpdate command, and I've putted the cursor on the TextBox that's connected to the DB. Again, the changes were saved instead of being canceld.
So - if I try to do SOME action on the DB (including MoveNext, CancelUpdate, Update, AddNew etc..) while any control that is connected to the DB is focused the change will be saved to the DB.
Any idea why or what can I do about it?
Thank you very much,
Dave.
 
Yeah. Check the WillMove, WillChangeRecord, and WillChangeField events of your data control. Your cancelupdate should go somewhere in there.

Good luck-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top