Undo change command button not working

Zorkmid

Registered User.
Local time
Today, 06:56
Joined
Mar 3, 2009
Messages
188
Hi guys,

I have a command button that no longer seems to work and I'm wondering what is going on.

The button is in a subform linked to a search form, and it's purpose is to undo any changes that the user has made in the subform. Nothing happens when it is clicked, it used to work and I'm not sure what is diferrent now.

Code:
Private Sub CancelChanges_Click()
On Error GoTo Err_CancelChanges_Click
If Me.Dirty = True Then
    
    If MsgBox("Are you sure you wish to exit without making changes? Any unsaved information will be lost. Please Click OK to Continue or Cancel to Return to the form", vbOKCancel) = vbOK Then
        'If ok then undo unsaved changes:
        DoCmd.DoMenuItem acFormBar, acEditMenu, acUNDO, , acMenuVer70
        'Then close form:
        DoCmd.Close
        End If
    End If
If Me.Dirty = False Then
    'If no changes close form:
    DoCmd.Close
    DoCmd.OpenForm "Main_Page"
End If
Exit_CancelChanges_Click:
Exit Sub
Err_CancelChanges_Click:
Resume Exit_CancelChanges_Click
End Sub

Thanks!

-Z
 
my first thought is that [Event Procedure] is missing from the property sheet.

other suggestions in the code:

Code:
Private Sub CancelChanges_Click()
On Error GoTo Err_CancelChanges_Click
If Me.Dirty Then    [COLOR=green]'= True   not necessary[/COLOR]
 
    If MsgBox("Are you sure you wish to exit without making changes? Any unsaved information will be lost. Please Click OK to Continue or Cancel to Return to the form", vbOKCancel) = vbOK Then
        'If ok then undo unsaved changes:
        DoCmd.DoMenuItem acFormBar, acEditMenu, acUNDO, , acMenuVer70
        'Then close form:
        DoCmd.Close    [COLOR=green]'attempting to close a subform? you may need[/COLOR]
[COLOR=green]                             'DoCmd.Close acForm, Me.Parent[/COLOR]
        End If
    End If
[COLOR=green]Else[/COLOR]
[COLOR=sienna]'( If Me.Dirty = False Then )[/COLOR]
    'If no changes close form:
    DoCmd.Close    [COLOR=green]'close what?[/COLOR]
    DoCmd.OpenForm "Main_Page"
End If
Exit_CancelChanges_Click:
Exit Sub
Err_CancelChanges_Click:
Resume Exit_CancelChanges_Click
End Sub
 
my first thought is that [Event Procedure] is missing from the property sheet.

this has happened to me many a time (why? dunno). all you need to do is click on your button (in design view), open the properties, then click on the elipsis for the on click event. this should 'reconnect' the code to the control.

(edit: also, check that you haven't renamed your control since writing the code)
 
Hi guys,

I have a command button that no longer seems to work and I'm wondering what is going on.

Easy way to see:
1. If the cmd btn works
2. How the code executes

How to do it:
Open the code associated with the button and click in LHS "scroll bar" next to the "If Me.Dirty ...". A big brown dot appears and the "Me.Dirty ..." will also be brown. Save and return to the cmd btn and click on it. If the code can run you will get it on the screen at the brown dot. Pt 1 achieved.

Now press the <F8> key and the code will step thru one line at a time. Pt 2 achieved.

With many lines of code in a procedure this is a good way of isolating any unforeseen problems that might be occuring.
 
Oops, sorry I didn't reply to the thread, I kinda forgot, sorry.

It was just that the "[Event Procedure]" in the cmd button properties was missing. Not sure where it went though :P

-Z
 

Users who are viewing this thread

Back
Top Bottom