SmartestVEGA
SmartestVEGA

Reputation: 8889

BeforeUpdate issue - Runtime (error 2115)

I have written the following query:

Private Sub Size_Sqft_BeforeUpdate(Cancel As Integer)
  Me!Size_Sqft = Nz(Me!Size_Sqft, 0)
End Sub

But while removing the zero in the field to make it null, I am getting the following error:

Runtime error 2115

Macro and function set to before update and validation rule property for this field is preventing manual data entry screen for company from saving the data in the field.

Upvotes: 2

Views: 8501

Answers (2)

RubberDuck
RubberDuck

Reputation: 12728

I know this is an old thread, and has already been answered, but there is another solution that doesn't require several writes back to your database. I'm adding it in case someone else comes across this question.

Private Sub ControlName_BeforeUpdate(Cancel as integer)
    If isValid(Me.ControlName.Value) = False Then
        Cancel = True
        Me.ControlName.Undo
    End If
End Sub

Private Function isValid(ByVal...) as boolean
    ' validate control value here
End Function

Upvotes: 2

Tony Toews
Tony Toews

Reputation: 7882

You have to put that code in the AfterUpdate event of that field.

Upvotes: 2

Related Questions