Coding MsgBox Responses

N

NewKidontheBlock

As you can see from my display name, I am new to Access.

I have around 15 fields on a form which I don't want users to alter unless
they really have to, but occasions will arise when an update facility is
required.

If a user types new data into a field I want a message box to appear asking
whether they are sure the field is to be updated. Box should have OK and
cancel buttons. Ok to allow the alteration, and cancel to revert the field
contents back to the original.

Firstly, would this be a BeforeUpdate event?

And, secondly, how do I code the responses. It's what comes after the 'Then'
and 'Else' bits I'm after.

Kind regards

Tony
 
J

Joshua A. Booker

NewKid,

In the BeforeUpdate Event add this code:

If vbNo = MsgBox("Are you sure you want to do this?", vbYesNo + vbQuestion)
Then
Cancel = True
End If

HTH,
Josh
 
A

Al Camp

NewKid,
Assuming a text field...

Private Sub YourFieldName_BeforeUpdate(Cancel As Integer)
Dim Response As String
If Not IsNull(Field1.OldValue) Then
Beep
Response = MsgBox("Change Entry?", vbOKCancel)
If Response = vbCancel Then
Cancel = True
YourFieldName.Undo
End If
End If
End Sub

This code won't fire unless there was a value in YourFieldName, so when enetering a New
record, you won't have to respond to each entry.
 
Top