UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Retain Existing Data...?, Access 2016    
 
   
BShick5088
post Aug 14 2019, 11:14 AM
Post#1



Posts: 62
Joined: 15-January 11



Hi, Currently we have a form that is looking at the data from a table. When making changes the data it is being updated live in the table. How can I create a way for the user to close the form and DROP the changes made because of being on the wrong record.

My first thought was to use the form's "On Open" function and DIM all the fields and set them as the existing Public data. Then create a button on the form that will prompt the user they are about to "Drop All Changes", once excepted, pull back in all the set fields to the original data from when the form was opened. The problem is that I can't seem to get this to work. When a change is made it reverts the field that was DIM'ed to a blank or "" and effectively clears the field.

Does anyone have an example of how to drop changes made on a form to a table? Or better yet an easier way I am unaware of...!
Go to the top of the page
 
theDBguy
post Aug 14 2019, 11:27 AM
Post#2


Access Wiki and Forums Moderator
Posts: 76,300
Joined: 19-June 07
From: SunnySandyEggo


Hi. Not sure what your situation is exactly but I always say it's better to avoid a problem than to fix it. How come the data is stored in the wrong record? Was that just a "for example" scenario?

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
BShick5088
post Aug 14 2019, 02:41 PM
Post#3



Posts: 62
Joined: 15-January 11



Hi, Agreed... but "What If" a user has opened one record and made the changes that should be on another... then halfway through figures out it's wrong and wants to close the form and not save the changes.

Would something like this work?

Private Sub cmdDropChangesClose_Click()
'Drop Changes and Close the form
Dim answer As Integer
answer = MsgBox("Are you sure you want to Drop all changes and close this window?", vbYesNo + vbQuestion, "YOU ARE ABOUT TO DROP ALL CHANGES!")
If answer = vbYes Then
Me.Undo
DoCmd.Close
End If

End Sub


Maybe this is the rout I should take...?
Go to the top of the page
 
theDBguy
post Aug 14 2019, 03:02 PM
Post#4


Access Wiki and Forums Moderator
Posts: 76,300
Joined: 19-June 07
From: SunnySandyEggo


Hi. If a user wants to cancel any changes to the data before it is saved to the table, all he/she has to do is hit the Esc key - no code required. However, if you do want to use code, the typical approach is to use the Form's BeforeUpdate event to validate the data changes.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
missinglinq
post Aug 14 2019, 06:32 PM
Post#5



Posts: 4,634
Joined: 11-November 02



Here's code that does what theDBguy is talking about...with the additional benefit of asking if the data entered in a New Record is to be saved or dumped:
CODE
Private Sub Form_BeforeUpdate(Cancel As Integer)

If Not (Me.NewRecord) Then
  If MsgBox("Would You Like To Save The Changes To This Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save Changes to Record ???") = vbNo Then
   Me.Undo
  End If
Else
  If MsgBox("Would You Like To Save This New Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save This New Record ???") = vbNo Then
   Me.Undo
  End If
End If

End Sub

Linq ;0)>
This post has been edited by missinglinq: Aug 14 2019, 06:33 PM

--------------------
Hope this helps!

The problem with making anything foolproof...is that fools are so darn ingenious!

All posts/responses based on Access 2003/2007
Go to the top of the page
 
DanielPineault
post Aug 14 2019, 06:49 PM
Post#6


UtterAccess VIP
Posts: 6,838
Joined: 30-June 11



Why not open the form blank and force the user to retrieve a record, so they have to take 100% ownership of the data they are working on/with as they selected it.

Another option is go the route of an unbound form with a save and close button, and add a confirmation process to the save button.

--------------------
Daniel Pineault (2010-2019 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    17th September 2019 - 05:29 AM