Solved

Message box problem

Posted on 2006-10-31
8
267 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

Suggested Solutions

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

810 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