Solved

Message box problem

Posted on 2006-10-31
8
284 Views
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.Close
 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.
    DoCmd.Close

Exit_Cancel_Click:
    Exit Sub

Err_Cancel_Click:
    MsgBox Err.Description
    Resume Exit_Cancel_Click
0
Comment
Question by:Dotrooney
[X]
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
8 Comments
 
LVL 77

Expert Comment

by:peter57r
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?)


Pete
0
 
LVL 42

Expert Comment

by:dqmq
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
0
 

Author Comment

by:Dotrooney
ID: 17848078
Pete

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.
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

Author Comment

by:Dotrooney
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
0
 
LVL 34

Expert Comment

by:jefftwilley
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.

0
 

Author Comment

by:Dotrooney
ID: 17849737
jefftwilly

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

Accepted Solution

by:
jefftwilley earned 125 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
0
 

Author Comment

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

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

737 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