Solved

Message box problem

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

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

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…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now