Access VBA Compile Error Sub or Function not defined

Hi

In my Access VBA code below, the Sub Form_BeforeUpdate code causes an error "Compile Error Sub or Function not defined"

Private blnSaved As Boolean

Private Sub Form_BeforeUpdate(Cancel As Integer)
    If blnSaved = False Then
        Cancel = True
        Me.Undo
        Cancel = False
    End If
End Sub

Private Sub Form_Current()
    blnSaved = False
End Sub

Private Sub btnOK_Click()
    blnSaved = True
    MsgBox "Changes saved!"
End Sub

Private Sub btnCancel_Click()
    DoCmd.Close
End Sub

Open in new window

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
1. Go to form properties, look at the BeforeUpdate event, should read "[Event Procedure]".   Click the builder button ( three dots) off to the right.

 Should bring you to your code.

2. In your before update code, you only need to do this:

Private Sub Form_BeforeUpdate(Cancel As Integer)

    If blnSaved = False Then
        Cancel = True
    End If

End Sub

 To cancel the event (and the save).  This leaves it as the user left it.   At that point, they could click a "Save" button.

Jim.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gustav BrockCIOCommented:
You should at least close one question before continuing it in a new question:

https://www.experts-exchange.com/questions/29080811/Access-VBA-Code-to-stop-data-saving-to-tables.html
0
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.