Error 2115 in controls Before Update event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi gang!
I'm getting error 2115 'The macro or function set to the Before Update
property for this field is preventing the application from saving the data in
the field.'
in a Before Update event of a control.
The control is not bound.
The code basically just trims the length of the string entered if it exceeds
the fields size.

Here's the code:

Private Sub txtName_BeforeUpdate(Cancel As Integer)
If Len(txtName.Value) > 80 Then
txtName.Value = Left(txtName.Value, 80)
MsgBox "The name you have entered exceeds our limit of 80 characters!"
End If
End Sub

The error occurs on the line txtName.Value = Left(txtName.Value, 80)
I tried using .Text instead of .Value, but that mde no difference.

Any ideas?

Access XP, WinXP SP2, SQLServer 2000

Thanks!
 
Hi,
From your description, I understand that:
If the textbox input value is over 80, you want to modify its value to 80
in its BeforeUpdate event, however an error occurred. The error message was:
2115 'The macro or function set to the Before Update
property for this field is preventing the application from saving the data
in
the field.'
If I have misunderstood, please let me know.

This is a limitation by design. A run-time error will occur if you attempt
to modify the data contained in the control that fired the BeforeUpdate
event in the event's procedure.
Generally we use BeforeUpdate event to perform validations.
You can refer to:
BeforeUpdate Event [Access 2003 VBA Language Reference]
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/htm
l/acevtBeforeUpdate_HV03079783.asp

I recommend that you use LostFocus event to carry out this validation and
change the value that exceeds 80.

Sincerely,
Charles Wang
Microsoft Online Community Support

======================================================
When responding to posts, please "Reply to Group" via
your newsreader so that others may learn and benefit
from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
======================================================
 
You must put it in the AfterUpdate event of the control or in the
BeforeUpdate event of the form.

Also, truncating the value is not user friendly. Instead, you should only
display an error message and set Cancel to True so that the user can make
the correction himself.
 
Many Thanks!

Sylvain Lafontaine said:
You must put it in the AfterUpdate event of the control or in the
BeforeUpdate event of the form.

Also, truncating the value is not user friendly. Instead, you should only
display an error message and set Cancel to True so that the user can make
the correction himself.
 
Back
Top