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
Ron Henry - 30 Jan 2006 22:48 GMT
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.
> Dear Access 2003 Users,
>
[quoted text clipped - 8 lines]
>
> Kevin
cjb_kjb - 30 Jan 2006 22:52 GMT
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
Larry Linson - 31 Jan 2006 02:48 GMT
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
> Put an event procedure on the on change event.
>
[quoted text clipped - 10 lines]
>
> End Sub
fredg - 31 Jan 2006 01:48 GMT
> Dear Access 2003 Users,
>
[quoted text clipped - 8 lines]
>
> 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

Signature
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
No Spam - 31 Jan 2006 18:11 GMT
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!
>> Dear Access 2003 Users,
>>
[quoted text clipped - 16 lines]
> End If
>End If
No Spam - 31 Jan 2006 19:22 GMT
It looks like Nz did the trick!
>Thanks to everyone who helped with this! One added request - if
>someone highlights the data in the field, deletes it, and moves on,
[quoted text clipped - 22 lines]
>> End If
>>End If