Warning after making changes

J

jppigao

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
 
K

krissco

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
 
S

Steve

You can put code in the form's BeforeUpdate event to raise a message. A
form's BeforeUpdate event fires when anything in a record is changed but
before it is saved. Thus you could cancel the update in the code and revert
any changes back to the original data. The only problem you would have to
work out is that this event would fire if the user wanted to actually edit a
record and would fire for all new records.

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
(e-mail address removed)
 
J

Jeff Boyce

If your .mdb file is not informing you when it saves changes you've made,
perhaps the internal "warnings" have been turned off.

Open a new macro, select the "Set Warnings" action, and turn them on. Run
the macro.

Are you still able to make changes without notice/warning?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
G

George Nicholson

If your .mdb file is not informing you when it saves changes you've made,
perhaps the internal "warnings" have been turned off.

Another thing to check: Tools>Options: Confirm - Record Changes is checked.

HTH,
 
J

jppigao

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- Hide quoted text -

- Show quoted text -

Kris....thanks for this code and now it is working in my database. God
bless and more power.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top