469,610 Members | 1,771 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

Is There A Way to Pop Up a MessageBox Warning When User Changes Data?

Dear Access 2003 Users,

Is there a way to pop up a MessageBox warning when a user changes data
on a form? Basically, I have one field that I really want people to
think about before changing, so when they get to that field (which is
the first tab stop on a continuous form), if there is data in it and
they change it, I would love a MessageBox popping up saying "Are you
sure that you want to change XXXX to YYYY?". If they hit Yes, the
changes are applied, No they revert back to the other data. Any
ideas? Thanks!

Kevin
Jan 30 '06 #1
6 8189
I have something similar, but it is set on the entire for. The code
runs on the before update.

Here is the code.

Private Sub Form_BeforeUpdate(Cancel As Integer)

'confirm with user that this record is to be modified

Dim updRecord As Byte

On Error GoTo Form_BeforeUpdate_Error

updRecord = MsgBox("Confirm record change", vbOKCancel, "Record
Modification")

If updRecord = vbCancel Then
Cancel = True

End If

'Dim priordate As Variant
'Dim prioruser As Variant
Me!DateModified = Now()
Me!UserModified = CurrentUser()

On Error GoTo 0
Exit Sub

Form_BeforeUpdate_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure Form_BeforeUpdate of VBA Document Form_Customers"
End Sub

Hope this helps.

"No Spam" <no****@earthlink.net> wrote in message
news:oh********************************@4ax.com:
Dear Access 2003 Users,

Is there a way to pop up a MessageBox warning when a user changes data
on a form? Basically, I have one field that I really want people to
think about before changing, so when they get to that field (which is
the first tab stop on a continuous form), if there is data in it and
they change it, I would love a MessageBox popping up saying "Are you
sure that you want to change XXXX to YYYY?". If they hit Yes, the
changes are applied, No they revert back to the other data. Any
ideas? Thanks!

Kevin


Jan 30 '06 #2
Put an event procedure on the on change event.

Then put the following code in the event procedure:

Field - is the name of the field on the form. Change this to the field
name that is on your form.

Private Sub Field_Change()

If MsgBox("do you want to change this ?", vbYesNo) = vbNo Then
Me!Field.Undo
End If

End Sub

Jan 30 '06 #3
On Mon, 30 Jan 2006 22:30:04 GMT, No Spam wrote:
Dear Access 2003 Users,

Is there a way to pop up a MessageBox warning when a user changes data
on a form? Basically, I have one field that I really want people to
think about before changing, so when they get to that field (which is
the first tab stop on a continuous form), if there is data in it and
they change it, I would love a MessageBox popping up saying "Are you
sure that you want to change XXXX to YYYY?". If they hit Yes, the
changes are applied, No they revert back to the other data. Any
ideas? Thanks!

Kevin


Code that control's AfterUpdate event:

If Me!ControlName.OldValue <> Me!ControlName Then
If MsgBox("Are You sure", vbYesNo) = vbNo Then
Me!ControlName = Me!ControlName.OldValue
End If
End If
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Jan 31 '06 #4
Probably not where you want to put the code -- on change fires on each
keystroke. BeforeUpdate is a good place... if they respond that they do not
want to change, it has a Cancel argument to cancel the update.

Larry Linson
Microsoft Access MVP

"cjb_kjb" <cj*****@hotmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Put an event procedure on the on change event.

Then put the following code in the event procedure:

Field - is the name of the field on the form. Change this to the field
name that is on your form.

Private Sub Field_Change()

If MsgBox("do you want to change this ?", vbYesNo) = vbNo Then
Me!Field.Undo
End If

End Sub

Jan 31 '06 #5
Thanks to everyone who helped with this! One added request - if
someone highlights the data in the field, deletes it, and moves on,
this code does not capture that. Any ideas!

Thanks a million!

On Mon, 30 Jan 2006 17:48:45 -0800, fredg <fg******@example.invalid>
wrote:
On Mon, 30 Jan 2006 22:30:04 GMT, No Spam wrote:
Dear Access 2003 Users,

Is there a way to pop up a MessageBox warning when a user changes data
on a form? Basically, I have one field that I really want people to
think about before changing, so when they get to that field (which is
the first tab stop on a continuous form), if there is data in it and
they change it, I would love a MessageBox popping up saying "Are you
sure that you want to change XXXX to YYYY?". If they hit Yes, the
changes are applied, No they revert back to the other data. Any
ideas? Thanks!

Kevin


Code that control's AfterUpdate event:

If Me!ControlName.OldValue <> Me!ControlName Then
If MsgBox("Are You sure", vbYesNo) = vbNo Then
Me!ControlName = Me!ControlName.OldValue
End If
End If


Jan 31 '06 #6
It looks like Nz did the trick!

On Tue, 31 Jan 2006 18:11:07 GMT, No Spam <no****@earthlink.net>
wrote:
Thanks to everyone who helped with this! One added request - if
someone highlights the data in the field, deletes it, and moves on,
this code does not capture that. Any ideas!

Thanks a million!

On Mon, 30 Jan 2006 17:48:45 -0800, fredg <fg******@example.invalid>
wrote:
On Mon, 30 Jan 2006 22:30:04 GMT, No Spam wrote:
Dear Access 2003 Users,

Is there a way to pop up a MessageBox warning when a user changes data
on a form? Basically, I have one field that I really want people to
think about before changing, so when they get to that field (which is
the first tab stop on a continuous form), if there is data in it and
they change it, I would love a MessageBox popping up saying "Are you
sure that you want to change XXXX to YYYY?". If they hit Yes, the
changes are applied, No they revert back to the other data. Any
ideas? Thanks!

Kevin


Code that control's AfterUpdate event:

If Me!ControlName.OldValue <> Me!ControlName Then
If MsgBox("Are You sure", vbYesNo) = vbNo Then
Me!ControlName = Me!ControlName.OldValue
End If
End If


Jan 31 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by s-galit | last post: by
4 posts views Thread by Tressa | last post: by
4 posts views Thread by mac | last post: by
2 posts views Thread by randy1200 | last post: by
6 posts views Thread by Goran Djuranovic | last post: by
5 posts views Thread by Cubicle Intern | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.