Solved

Message box problem

Posted on 2006-10-31
8
275 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
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

840 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