Error 2115 in controls Before Update event

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!
 
C

Charles Wang[MSFT]

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.
======================================================
 
S

Sylvain Lafontaine

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.
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top