Re: Warning after making changes

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Aug 28, 6:28 am, jppi...@xxxxxxxxx wrote:
Hello people,

As i'm trying to test my program from time to time i have notice that
i change a lot of data without any notice from the program, now do we
have any source or code to warn a user if he accidentally changes
something in the form or maybe in the record itself? But if he press
the Save button that warning will not appear anymore of course.

So basically what i am thinking of right now. I wanted to have a
security in my database so in case the user changes accidentally some
information in the database he will receive a warning but if he
decided to save the database no warning will appear and he can
continue making some manual input.

Have a grat day, this forum is perfect for me as a beginner in
Access!

John Paul

John Paul,

Here are my assumptions:
I assume your data is in tables.
I assume your users change data using a form and not through the table
itself.
I assume you can code in VBA.
I also assume the form is bound and that the user is not executing
UPDATE queries.

You can warn the user by placing code in the Form's BeforeUpdate
event. There are two tricks here:
1. Don't execute the warning code when the user explicitly clicks your
"Save" button.
2. Prompt/warn the user and retrieve their response.


Let's handle that Save button first.
Create a button on your form called "btnSave"
Set the OnClick event of that button to [EventProcedure]
Edit the module of the form. At the top of the form (after the Option
statement(s) but before any functions) place the following line:
Dim blIgnoreWarning as Boolean
In the OnClick event, add the following two lines:
blIgnoreWarning = true
me.refresh
This will "flag" the record as explicitly saved, and write the data
back to the table.
Set the Form's OnCurrent event to [EventProcedure].
Add the following line of code to the OnCurrent event:
blIgnoreWarning = false
This will reset the flag whenever a new record is accessed.

Now let's handle your warning.
Set the BeforeUpdate event of the Form to [EventProcedure]
Your procedure will look something like this:

Private sub Form_BeforeUpdate(Cancel as Integer)

'A variable to hold the user's response
dim lngRet as long

'If the form was not explicitly saved, prompt the user
if not blIgnoreWarning then

'Prompt the user and record their input
lngRet = MsgBox("Data Was Changed. Do you want to save?", vbYesNo)

'If the user answers yes, then save. Else, cancel & undo the
editing.
if lngRet = vbYes then
'Save is implicit. Don't need to add code
else
Cancel = true
Me.Undo
end If

end if
End Sub


-Kris

.



Relevant Pages

  • Re: Warning after making changes
    ... the Save button that warning will not appear anymore of course. ... security in my database so in case the user changes accidentally some ... Dim blIgnoreWarning as Boolean ... lngRet = MsgBox("Data Was Changed. ...
    (microsoft.public.access.reports)
  • Re: SW File Permissions
    ... Yet I can make changes to dimensions, features, etc.. ... Changes to dimensions results in a warning "that it is read-only" and ... that any changes I make will be lost unless I do a saveas. ... ignore the prompt, fill in new value and part/assembly are updated ...
    (comp.cad.solidworks)
  • Re: Recovering from temp directory
    ... if you want to "Open it" or "Save it to disk". ... So let's suppose Microsoft created a message when opening a document ... in the Temp folder without warning. ... There should be a prompt in this ...
    (microsoft.public.word.application.errors)
  • Required Fields and Warning Boxes
    ... warning box to appear asking the user "are you sure you want to make ... field and shows the confirmation box but the information in the form ... Second Script: When I create a separate function with "are you sure ... it does not prompt me to complete the email field. ...
    (comp.lang.javascript)
  • Re: Best way to cancel out of a data entry form?
    ... You can turn the warning off with: ... DoCmd.DoMenuItem acFormBar, acEditMenu, 8,, acMenuVer70 ... to change the prompt to 'are you sure you want to cancel'? ...
    (microsoft.public.access.forms)