Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Confirm before Update 1

Status
Not open for further replies.

njitter

Technical User
Sep 4, 2001
122
0
0
US
Hello,

i have a form with a Boolean Box on it. I want the user to confirm the change of the value before updating the database.

I have this now:

Private Sub History_BeforeUpdate(Cancel As Integer)
If MsgBox("Change History status?", vbOKCancel, "History")= vbCancel Then
Me.History.Undo
End If
End Sub

This does not work. I get the Popup but the Undo does not work.. Any suggestions?

Regards,

Njitter

---
It's never too late to do the Right thing
 
I have this on the BeforeUpdate event of the form. You can change it:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
strMsg = "Data has changed."
strMsg = strMsg & "@Do you wish to save the changes?"
strMsg = strMsg & "@Click Yes to Save or No to Discard changes."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes Then
'do nothing
Else
DoCmd.RunCommand acCmdUndo
End If
End Sub

Neil
 
Neil,

i want the window to appear on the Boolean Flag. It's to remind the users of the impact of the flag they are changing.

Code:
Private Sub History_BeforeUpdate(Cancel As Integer)

Dim strMsg As String
    strMsg = "Data has changed."
    strMsg = strMsg & "@Do you wish to change the status?"
    strMsg = strMsg & "@Click Yes to Change or No to Discard changes."
    If MsgBox(strMsg, vbQuestion + vbYesNo, "Change Status?") = vbYes Then
        'do nothing
    Else
        DoCmd.RunCommand acCmdUndo
     End If
End Sub

If i execute this form i get:

---

Run-time error '2046':

The command or action 'Undo' isn't available now.

* You may be in a read-only database or an unconverted database from an earlier version of DMF Numbers en Modules.
* The type of object the action applies to isn't currently selected or isn't in the active view.

---

Any suggestions?

Regards,

Njitter

---
It's never too late to do the Right thing
 
I fixed it by doing it the other way around:

Code:
Private Sub History_AfterUpdate()
Dim Old_Value

Old_Value = History.OldValue

Dim strMsg As String
    strMsg = strMsg & "@Do you wish to change the status?"
    strMsg = strMsg & "@Click Yes to Change or No to Discard changes."
    If MsgBox(strMsg, vbQuestion + vbYesNo, "Change Status?") = vbYes Then
       'Continue
    Else
        History.Value = Old_Value
     End If
End Sub

This way the status is switched back to the old value if 'No' is selected, otherwise the status stays the same.

Njitter

---
It's never too late to do the Right thing
 
hello,
suppose i just want to have this message popup when it's an old record & not a new 1, HOW can i do it?
Jinan74
 
Hi njitter,

The reason your Undo doesn't work is because there isn't anything to undo. Your (original) code was in the BeforeUpdate event. In this event you just set Cancel to True to stop the update happening ..

Code:
Private Sub History_BeforeUpdate(Cancel As Integer)

Dim strMsg As String
    strMsg = "Data has changed."
    strMsg = strMsg & "@Do you wish to change the status?"
    strMsg = strMsg & "@Click Yes to Change or No to Discard changes."
    If MsgBox(strMsg, vbQuestion + vbYesNo, "Change Status?") = vbYes Then
        'do nothing
    Else
Code:
Cancel = true
Code:
     End If
End Sub

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
You can also use
DoCmd.CancelEvent
to abort deletion/update/insertion.

MakeItSo
 
Sorry Jinan,
it was such a short line, guess I overread it. [blush]

Simply surround the message popup with
If not Me.NewRecord
..
End If

[wavey]
 
thank u Make it so, that's the answer i've been looking 4, i grant u a star :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top