2
votes

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.

2

2 Answers

2
votes

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

2
votes

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