Usening vb yes no & Cancel!

Crash1hd

Registered CyberGeek
Local time
Today, 07:05
Joined
Jan 11, 2004
Messages
143
Ok I have the following code

PHP:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Checkme <> True Then
Dim strMsg As String
    strMsg = "Data has changed."
    strMsg = strMsg & "Do you wish to save the changes?" & Chr(13)
    strMsg = strMsg & "Click Yes to Save or No to Discard changes."

Select Case MsgBox(strMsg, vbQuestion + vbYesNoCancel, "Save Record?")
    Case Is = vbYes
        'MsgBox "Yes"
        'do nothing
    Case Is = vbNo
        'MsgBox "No"
        DoCmd.RunCommand acCmdUndo
        CancelYes = False
    Case Is = vbCancel
        'MsgBox "Cancel"
        CancelYes = True
End Select
End If
End Sub

Sub Form_Unload(Cancel As Integer)
On Error GoTo Form_Unload_Err
If CancelYes <> True Then
    If ParentFormIsOpen() Then Forms![Employees1]!ToggleLink = False
    If Me.TTotal_Score <> "" Then
    Dim RaRound
    Checkme = True
    RaRound = DCount("[Initials]", "Inbound", "[Initials] = [Forms]![Inbound]![Initials]")
    If [Forms]![Inbound]![RRound] <> "" Then
    Else
        If RaRound = "1" Then
            [Forms]![Inbound]![RRound] = "1"
        Else
            [Forms]![Inbound]![RRound] = RaRound
        End If
    End If
    End If
Else
    'MsgBox ("This will stop it from closing")
    DoCmd.CancelEvent
    CancelYes = False
End If
Form_Unload_Exit:
    Exit Sub

Form_Unload_Err:
    MsgBox ("Not ME") 'Error$
    Resume Form_Unload_Exit

End Sub

works great but when I press the cancel button it stops the action and doesnt undo (which is what I want) but now if I where to click close it doesnt ask anymore, I know that is due to it no longer thinking that the change that was made is no longer new so I thought if I changed

Case Is = vbCancel
'MsgBox "Cancel"
CancelYes = True

to

Case Is = vbCancel
'MsgBox "Cancel"
CancelYes = True
DoCmd.RunCommand acCmdUndo
DoCmd.RunCommand acCmdRedo

That would fix the problem as it would undo the change and then redo the change but the acCmdRedo doesnt work so how else can I tell access that the change that was made is still new and not an old change so that when the user closes for a 2nd time without making anymore changes they are prompted again :confused:
 
In the message box, you are giving the users a choice of Yes or No. Why then, are you allowing a Cancel button as well?
Also, you are firing the event on the Before_Update which will only fire if you have made changes to the record. Why do you need to ask the client if they want to save changes if they haven't made any?
 
Ok I only want it to ask when they have made a change! Have you ever tried to close notepad without saving they have a cancel button when you click yes it saves the changes and closes the window when you click no it disgards the changes and closes the window. When you click Cancel it does nothing but keep the window open (A way of stopping the user from accedentaly closing a window that they dont want to close. However If you are to close the window again even though you havent made any changes the second time it still asks if you want to save or disregard or cancel the action! I am trying to achieve the same results :)
 
Stick to one post on the subject so members aren't giving duplicate responses!
 

Users who are viewing this thread

Back
Top Bottom