Dotrooney
asked on
Message box problem
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
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
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
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
ASKER
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.
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.
ASKER
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
If msgbox("Are you sure?",vbSaveCancel) = vbCancel then
cancel = True
end if
However, it still has allowed the new value in the field
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.
ASKER
jefftwilly
I have tried that and it still won't work -see my comment 12:19
I have tried that and it still won't work -see my comment 12:19
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Its working now, thanks to everyone who helped
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