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?
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.