Clear and Exit Form

jkmyers

New member
Local time
Today, 12:29
Joined
Mar 24, 2011
Messages
2
I am trying to create a command button that clears the form and exits without saving a blank record. Every code I have tried will clear and exit, but then my table had a blank entry.

Any help would be much appreciated.
 
For this I cheat a little (I use the code thats created via the button wizard), I would use the code below to undo the last record and then just exit.

Granted you will want a IF statment if you want to warn a user etc.


Code:
'------------------------------------------------------------
' Command5_Click
'
'------------------------------------------------------------
Private Sub Command5_Click()
On Error GoTo Command5_Click_Err
    On Error Resume Next
    DoCmd.RunCommand acCmdUndo
    If (MacroError <> 0) Then
        Beep
        MsgBox MacroError.Description, vbOKOnly, ""
    End If
 
Command5_Click_Exit:
    Exit Sub
Command5_Click_Err:
    MsgBox Error$
    Resume Command5_Click_Exit
End Sub
 
Thank you for the response.

However, I get an error

"Compile error:

Can't find project or library"

MacroError is highlighted.

Any thoughts??

Thanks again!!
 
My suggestion is to just put this in the form's Before Update event:
Code:
If blnSave = False Then
   Cancel = True
   Me.Undo
End If

And then you declare blnSave in the General Declarations section of a standard module:
Code:
Public blnSave As Boolean

And then when you DO want to save you set blnSave to True and it will bypass the If that we put into the before update event.


That is just another suggestion.
 

Users who are viewing this thread

Back
Top Bottom