Re: Warning after making changes
- From: krissco <kris.scorup@xxxxxxxxx>
- Date: Tue, 28 Aug 2007 15:05:03 -0000
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
.
- References:
- Warning after making changes
- From: jppigao
- Warning after making changes
- Prev by Date: Re: Report Footer Help Needed Please
- Next by Date: Re: Best way to build a report
- Previous by thread: Warning after making changes
- Next by thread: Re: Warning after making changes
- Index(es):
Relevant Pages
|