By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,827 Members | 2,220 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,827 IT Pros & Developers. It's quick & easy.

Prevent update when user exits a text box

P: 4
I have a form with a number of bound text boxes on it. When the form opens, it retrieves data from a table. I want the user to change data in one or more of the text boxes without any data from the form updating the table until the user presses a "save" button.

Simply, I want the user to see in the form the data that they want changed without it impacting the database in any way until a "save" button is pressed.

I tried putting DoCmd.CancelEvent into the BeforeUpdate event. The problem I have at that point is that the system will not permit the user to leave that text box.

I have also tried using "undo" in the AfterUpdate" event. Ignoring the overhead, this seemed to work until leaving the form and then the table was updated.

Is there a simple way to "turn off" the updating by Access within a form until I programmatically perform the save? I am reluctant to make the text boxes unbound because on some forms I have a lot of text boxes.
Dec 11 '06 #1
Share this Question
Share on Google+
7 Replies


ADezii
Expert 5K+
P: 8,615
I have a form with a number of bound text boxes on it. When the form opens, it retrieves data from a table. I want the user to change data in one or more of the text boxes without any data from the form updating the table until the user presses a "save" button.

Simply, I want the user to see in the form the data that they want changed without it impacting the database in any way until a "save" button is pressed.

I tried putting DoCmd.CancelEvent into the BeforeUpdate event. The problem I have at that point is that the system will not permit the user to leave that text box.

I have also tried using "undo" in the AfterUpdate" event. Ignoring the overhead, this seemed to work until leaving the form and then the table was updated.

Is there a simple way to "turn off" the updating by Access within a form until I programmatically perform the save? I am reluctant to make the text boxes unbound because on some forms I have a lot of text boxes.
'I didn't research this problem extensively but this logic should work:

1) Dimension a Form Level Variable as such: (the name is irrelevant)
Expand|Select|Wrap|Line Numbers
  1. Private blnRecordSaved As Boolean
2) In the Change() Event of all Form Controls:
Expand|Select|Wrap|Line Numbers
  1. blnRecordSaved = False
3) In the Click() Event of a Save Record button:
Expand|Select|Wrap|Line Numbers
  1. blnRecordSaved = True
  2. DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
4) In the Form's BeforeUpdate() Event:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.   If blnRecordSaved = True Then
  3.     'Do nothing
  4.   Else
  5.     Cancel = True
  6.   End If
  7. End Sub
Dec 11 '06 #2

P: 4
Thanks for the suggestion.

I have tried it, and unfortunately I wind up with the same problem. When I change a value in a text box with the Before Update logic present, the cursor gets "stuck" in that text box. The only way to move is to press "esc" so that the value goes back to what it was before the user changed it.
Dec 12 '06 #3

ADezii
Expert 5K+
P: 8,615
Thanks for the suggestion.

I have tried it, and unfortunately I wind up with the same problem. When I change a value in a text box with the Before Update logic present, the cursor gets "stuck" in that text box. The only way to move is to press "esc" so that the value goes back to what it was before the user changed it.
'I duplicated the problem exactly with the logic that I previously outlined and
'it seems to work like a charm - the cursor does not get "stuck". Will research
'the problem further for you...
Dec 12 '06 #4

P: 4
Thanks again, your help is very much appreciated.

Just to make sure that I am explaining my situation correctly. I have a bound textbox on the form and the table has text data. In the field other than the Before Event I have nothing happening. My goal is for the user to enter/modify data in the various fields on the form and then at the end if they want to save the data to then press the save button and all the data then updates the record in the table.

Perhaps the problem has to do with the version of Access. I am using Access 2002. Is that the version that you are using?
Dec 12 '06 #5

NeoPa
Expert Mod 15k+
P: 31,299
Have you tried the Cancel WITH the Undo in the Form_BeforeUpdate() event?
Dec 12 '06 #6

P: 4
I tried your suggestion about putting an Undo into the Before Event. It indeed lets me out of the textbox but it restores the value that was in the box before the user made a change.

So far the coding that seems to work is to have an Undo in the AfterUpdate event. It is inefficient because I am doing an I/O in the before event to update the data and then another I/O in the after event to undo the update. This may be the only choice that I have.
Dec 12 '06 #7

NeoPa
Expert Mod 15k+
P: 31,299
If you put Cancel = True in the FORM_BeforeUpdate event I don't see why the control would have any problems unless :
1. The data is invalid for the control.
2. You are trying to move to another record.
Dec 12 '06 #8

Post your reply

Sign in to post your reply or Sign up for a free account.