DoCmd.RunCommand acCmdRedo Failure

Crash1hd

Registered CyberGeek
Local time
Today, 07:01
Joined
Jan 11, 2004
Messages
143
acCmdRedo???? Doesnt work?

Why is it that acCmdUndo works fine but the acCmdRedo doesnt do anything but give me errors?
 
well I was useing the following code

Code:
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
        DoCmd.RunCommand acCmdUndo
        DoCmd.RunCommand acCmdRedo
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

so that it would undo and then redo there by making access believe that the changes where new so that if the user closed the form they would be prompted by the msgbox again! :cool:
 
You had an extra "End If" and there is no point to do anything if you cancel something, but you should save it if its yes, try this:

Code:
Option Compare Database

Select Case MsgBox(strMsg, vbQuestion + vbYesNoCancel, "Save Record?")
    Case Is = vbYes
        'MsgBox "Yes"
        DoCmd.RunCommand acCmdSaveRecord
    Case Is = vbNo
        'MsgBox "No"
        DoCmd.RunCommand acCmdUndo
        CancelYes = False
    Case Is = vbCancel
        'MsgBox "Cancel"
        CancelYes = True
        'Do nothing
End Select
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
________
Toyota Hiace
 
Last edited:
ok but when you close the form it automatically saves the record so that code is not needed what I am trying to do is access puts up the msgbox when the record is closing only if there has been a change to the record useing the before update however if you cancle the action it stops the form from closing but the before update is no longer valed as there are no changes cause to its knowlede what is in there is now acurate cause it autosaves the content to the table before the action is canceled is there a way of stoping it from saving the table until I say so (remove autosave)?
 
Put your messagebox code into the Form_Unload event. It will then fire everytime you want to close the form.
 
Aside, if you can't find what's causing the error then comment out your On Error statement.
 
Ok I tried putting this in the Form_Unload and yes it ask everytime, problem is I only want it to ask when data has been changed, this is why its in the Form_BeforeUpdate field, so of course it will only ask when data has changed and when you click cancel it stops the action and no longer thinks that data has changed yet data is still different then what is in the table is there a way of comparing the data on the form with the data in the table, cause if you could compare the 2 then I could use that and only call the entire event when the data is different!

P.s. late reply was on holidays and back now :)
 
Ok why is it when you work on a problem no matter how long you work on it.... with in 10 mins of posting the question you figure out the answer??? :confused: It happens to me alot, not always as well seen in my previous post, but it does happen alot... I solved the mystery of this one I had to add an If then statement to the msgbox in the Form_Unload and then add a blah = true in the before update which then only made it check the msgbox when a changed has been made and now it checks everytime even when you click cancel! :D

So if anyone was wondering what the code was see below as I am sure others have had this problem

Code:
Dim Checkme 'Checks to see if it is checking to save from user input or internal changes
Dim CancelYes

Private Sub Form_BeforeUpdate(Cancel As Integer)
	Checkme = True
End Sub

Sub Form_Unload(Cancel As Integer)
On Error GoTo Form_Unload_Err
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 the 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
If CancelYes <> True Then
    If ParentFormIsOpen() Then Forms![Employees1]!ToggleLink = False
Else
    'MsgBox ("This will stop it from closing")
    DoCmd.CancelEvent
    CancelYes = False
End If

Form_Unload_Exit:
    Exit Sub

Form_Unload_Err:
    MsgBox Error$
    Resume Form_Unload_Exit

End Sub

Also can anyone help me figure out how to remove the second ok box that gets created when you click cancel it says

"you canceled the previous operation"

and you have to click ok to continue (I personaly hate it as it is redundant) obviously you clicked cancel maybe if you cant remove it? Then a way to change what it says??? :cool:
 
Last edited:
Well the problem was when I was canceling the event with the main part of the code in the before_update but I think i figured out where my problem was I had the actual part of the cancel in the unload section

If CancelYes <> True Then
If ParentFormIsOpen() Then Forms![Employees1]!ToggleLink = False
Else
'MsgBox ("This will stop it from closing")
DoCmd.CancelEvent
CancelYes = False
End If

so what was happening before was the event was firing I would hit cancel yet it would update the table before that they way I have it now works much better :) it was code that was givin to me and obviously was in accurate!
 
I believe you thats why what I did works cause the action never gets called unless the if is true and there has been a data change and the if will only ever be true if there is a data change :) I have just done it a little different then normal! :cool:
 

Users who are viewing this thread

Back
Top Bottom