Link to home
Start Free TrialLog in
Avatar of billcute
billcute

asked on

Help with Cancel Button Code

frmWater is bounded to tblWater. In the frmWater form, I have a "Cancel" button (btnCancel).

It is this button I want to modify to clear all currently entered data and starts a new blank page of frmWater when clicked.

The way I presently resolves the problem is by "DoCmd.Close" followed by "DoCmd.OpenForm "frmWater"  which makes refreshing of my form very slow. I will like to dsicard this method and use something much better. Any suggestion will be appreciated.

Here is my current code:
****************
Private Sub btnCancel_Click()
On Error GoTo Err_btnCancel_Click
If Me.Dirty Then
   Me.Undo
End If
'  DoCmd.Close                            <---- I want to remove this command and replace
                                                         it with something better
'  DoCmd.OpenForm "frmWater"   <--- I want to do away with this command
                                                        and replace it with something better
Exit_btnCancel_Click:
    Exit Sub
Err_btnCancel_Click:
    MsgBox Err.Description
    Resume Exit_btnCancel_Click
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of billcute
billcute

ASKER

LSMConsulting ,,
I discovered that sometimes when I click the "Cancel" button I get the following Microsoft Office Access error:

"The command or Action "RecordsGoToNew" isn't available right now"

LSMConsulting , What do you thibk is wrong? What needs to be fixed?
This normally occurs when you're already adding a new record ... try this:

If Me.Dirty Then Me.Undo
If Not Me.NewRecord Then DoCmd.RunCommand accmdRecordsGoToNew
I found out that my code already contain If Me.Dirty Then Me.Undo - and didnt make much difference.
Thanks for your assistance
<I found out that my code already contain If Me.Dirty Then Me.Undo - and didnt make much difference.>

Yes, I was merely including that line for reference ... I made the assumption that you wouldn't put it in twice.

Do you mean that the If Not Me.NewRecord didn't solve your trouble?
No..it didnt