Message box problem

Posted on 2006-10-31
Medium Priority
Last Modified: 2012-06-27
I have a message box that is activated on the Before Update event of a field. When a user edits the field I want them to stop and think whether their action is correct. The message box has a Save and a Cancel button but when you click Cancel, the field has still changed to the new value.

The On Click event of the Save button is
 DoCmd.RunCommand acCmdSaveRecord
    DoCmd.GoToRecord , , acNewRec

The On Click event of the Cancel button is
' This code created by Command Button Wizard.
On Error GoTo Err_Cancel_Click

    ' Close form.

    Exit Sub

    MsgBox Err.Description
    Resume Exit_Cancel_Click
Question by:Dotrooney
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 77

Expert Comment

ID: 17848057
Hi Dotrooney,

By Messagebox I am assuming you are talking about opening another form, which you have designed to look llike a messagebox.
I will take it for granted that a standard messagebox did not do what you needed.

But I am a bit puzzled by what is going on on the main form.
Is there only one field that can be edited on the main form?

(If so, what is the name of the form, and what is the name of the field?)

LVL 42

Expert Comment

ID: 17848068
Several odd things about that code.  The Save and Cancel buttons of a msgbox do NOT have on_click events.  So, I do not know what buttons the above events belong to. Nor do I understand why you want to close the form from a Save or Cancel button.

Anyway, what I suggest is this:

In the before_update event, raise the msgbox. If vbCancel is returned, then set cancel = True. for example:

If msgbox("Are you sure?",vbSaveCancel) = vbCancel then
  cancel = True
end if

Author Comment

ID: 17848078

Yes, I have created a form which looks like a messagebox. The form is called Frm Stock and Location ID (which is a combo box) is the name of the field, the rest of the fields are autofills from that combo box.
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.


Author Comment

ID: 17848160
dqmq, I have tried

If msgbox("Are you sure?",vbSaveCancel) = vbCancel then
  cancel = True
end if

However, it still has allowed the new value in the field
LVL 34

Expert Comment

ID: 17849655
What an annoying feature!! although it's a creative thing to have made the pop-up form and all that...use Dotrooney's suggestion in the Before_Update event of your combo box on your main form.


Author Comment

ID: 17849737

I have tried that and it still won't work -see my comment 12:19
LVL 34

Accepted Solution

jefftwilley earned 500 total points
ID: 17851098
Private Sub Combo9_BeforeUpdate(Cancel As Integer)
If MsgBox("Are you sure?", vbYesNo) = vbNo Then
  Cancel = True
End If

End Sub

Author Comment

ID: 17851627
Its working now, thanks to everyone who helped

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question