Using a VByesno message box

tina hayes

Registered User.
Local time
Yesterday, 20:27
Joined
Jul 28, 2004
Messages
37
Hi guys

i am looking at using some message boxes in a access database

i have two fields that can be changed but what i would like is that if you click in the fields and update the data when you click out a message box appears sayinf something like
are you sure you want to update this info, with a yes and a no button
if yes the data is updated if the no button is clicked then i would like it to revert back to the information that was in the box before

can anyone help please :p
 
hi tina,

try creating a code macro, using the AfterUpdate event and enter this:
Code:
If MsgBox("Do you wish to update?", vbYesNo, "CHECK") = vbYes Then
docmd.save (acForm,"FormName")
else
docmd.close (acForm,"FormName",acSaveNo)
docmd.open (acForm,"FormName")
endif
 
Last edited:
with OLDVALUE

confirm = MsgBox("are you sure you want to update?", vbYesNo, "UPDATE")
If confirm = 7 Then
Me![name] = Me![name].OldValue
End If
DoCmd.OpenForm "formName"
End Sub
 
Thankyou

Thanks guys i will go and try your solutions

many thanks for your time
 
You can do this two ways.

  1. By storing the result of the message box.
    Use this method if you know you will use the user's response and act accordingly on multiple occasions within the subsequent code.
    Code:
    Dim intResponse As Integer
    intResponse = MsgBox("Are you sure you wish to update?", vbQuestion + vbYesNo + vbDefaultButton1, "Update?")
    If intResponse = vbNo Then
        Me.MyControl.Undo
    End If
  2. By acting immediately on the response of the message box.
    Here we don't waste memory creating variables as we know the response will only be used once.
    Code:
    If MsgBox("Are you sure you wish to update?", vbQuestion + vbYesNo + vbDefaultButton1, "Update?") = vbNo Then
        Me.MyControl.Undo
    End If

Note that I have made three arguments relating the the style of the message box:

  1. vbQuestion: This puts a question mark icon into the message box.
  2. vbYesNo: This determines the buttons used in the message box.
  3. vbDefaultButton1: This determines the default button with the focus when the message box first appears.

The one thing you are missing, though, is that you are talking about updating a field value after it has been entered into a control. The whole record will only update once all work has concluded on the record and the form is no longer interested in it via either the form closing or moving to another record.
 

Users who are viewing this thread

Back
Top Bottom