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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Cancel to Prevent Save

Status
Not open for further replies.

vbaprogammer

Programmer
Sep 16, 1999
59
US
Brain dead?&nbsp;&nbsp;Senior Moment?<br><br>I have searched and read all variations of the methods suggested in this forum (which is the best I've found 'cause you guys are so smart) to prevent saving a record until a command button (Save) is clicked.<br><br>I have tried Cancel, Cycle Current Record, and all sorts of things.&nbsp;&nbsp;Too many errors to describe here.<br><br>Mats and Jim Horton made suggestions on April 14, but I was unable to convert their text descriptions to action.<br><br>I have three forms.&nbsp;&nbsp;One with a subform.&nbsp;&nbsp;I have a registrant for people and a subform for answers.&nbsp;&nbsp;At times the registrant info may change, and at times just the subform info changes.&nbsp;&nbsp;I would like to a) save the registrant info, save the answer info, or save both, but not until the user clicks the appropriate command buttons.&nbsp;&nbsp;The third form is registrants only, for batch entry of new registrants (this should have been simple).<br><br>The following has been suggested:&nbsp;&nbsp;BeforeUpdate, public variable, public variable set to false until click event (Cancel = ?), cycle current record (which has no effect), as well as others.<br><br>I can't seem to get all the pieces together in the proper order for the BeforeUpdate method.&nbsp;&nbsp;I really need a good example.<br><br>Am I correct that moving from record to record saves the data AND moving from field to field saves the data?&nbsp;&nbsp;My answer form has 40 fields just for answers.&nbsp;&nbsp;How do I prevent them from saving until all data is input.&nbsp;&nbsp;If a record is not COMPLETE, my report calculations are toast.<br><br>Would really appreciate some help.&nbsp;&nbsp;You all have been so helpful, just by answering questions for others, upon which I have eavesdropped.<br><br>Thanks<br><br>Dan
 
A solution might be to build a couple of temporary &quot;buffer&quot; tables that look exactly like your existing tables.<br><br>The idea here is that the data that they are entering is going to a temporary storage area.&nbsp;&nbsp;When the user hits the save button, an append query runs which appends the data from the temporary table to the main table<br><br>Make sure you run a delete query on the temp tables after the append query to clear it for the next record to be input.<br><br>Hope that helps.&nbsp;&nbsp;Good Luck<br><br>
 
Am I correct that moving from record to record saves the data AND moving from field to field saves the data?... Yes, you are correct.<br><br>1) To prevent the users from saving untill all the data given, you can use the form Before_Update event like this...<br><br>Private Sub Form_BeforeUpdate(Cancel As Integer)<br>&nbsp;&nbsp;&nbsp;' check your fields values here.<br>&nbsp;&nbsp;&nbsp;If Len(FieldName) = 0 Or IsNull(FieldName) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;enter a value&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cancel = True<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' to show the user where he sould put the data<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FieldName.SetFocus<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>End Sub<br><br>2) About the Save button, as i said the data is saved when the user moves from record to another, but you want the user to press the Save before the record saved.<br>Ok, so what about disable the default VCR naviagtion buttons and the record selectors. And make your own array of buttons (Next, Previous, Last, First) plus (Edit, Add, Delete, Save, Undo), the idea is to disable/enable these buttons upon the current mode of the record (naviagtion, Edit, or Add).<br>for example, if it's in the navigation mode, all the buttons are enable except the (Save, Undo). if it's in the Add or edit mode, all is disable except (Save, Undo). and in this case you can put your validation code in the click event of the Save button.<br><br>with this approach you can make sure that you have the full control of your users, and prevent them from hurting themseleves.<br><br>i hope that would help you...<br> <p>Mohamed Aly<br><a href=mailto:samara_79@hotmail.com>samara_79@hotmail.com</a><br><a href= > </a><br>
 
I really believe the Cancel method will work, but I don't know how to program it.<br><br>The example above shows the FORM BeforeUpdate event.&nbsp;&nbsp;Do I need a global variable, should I always use Cancel = True?&nbsp;&nbsp;Do I place Cancel = False in the button to save the data in the FORM, even though when i move from a field, the default is to save it.<br><br>Hate to be difficult, but this just escapes me.&nbsp;&nbsp;Can anyone provide me with detailed coding so I can get this through my brain.&nbsp;&nbsp;I would appreciate it.&nbsp;&nbsp;Cancel = True so it doesn't save????&nbsp;&nbsp;FORM or control????&nbsp;&nbsp;Just can't justify another table.<br><br>Thanks loads....<br><br>Dan
 
Moving from field-to-field does NOT save the record.&nbsp;&nbsp;Moving from record-to-record DOES save.<br><br>There is no good way to BOTH allow the user to make modifications to multiple fields in multiple records and SAVE or CANCEL the updates.<br><br>You should just design the application knowing that the modified row will cause the database to be updated when the user moves to the next row. <p>Jim Conrad<br><a href=mailto:jconrad3@visteon.com>jconrad3@visteon.com</a><br><a href= > </a><br>
 
The code i wrote above will NOT save the whole record which offcourse will not save the fields in that record...<br><br>in order to help you more, pls put your problem into pieces so we could slove it step by step <p>Mohamed Aly<br><a href=mailto:samara_79@hotmail.com>samara_79@hotmail.com</a><br><a href= > </a><br>
 
After reading your comments and (believe it or not), reading one of my reference books, I think I have it.<br><br>I'm going to test theory later, and if it works, will let you know.<br><br>And, yes, a good example would be easier to deal with.&nbsp;&nbsp;I'll provide code samples next time around.<br><br>Thanks for your help, y'all.<br><br>Dan
 
Now I'm facing a similar issue. How did you solve the problem, Dan?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top