Run-time error '2115'

  • Thread starter Thread starter cr113
  • Start date Start date
C

cr113

I'm getting the following error when trying to change the value of a
textbox. "Run-time error '2115'. The macro or function set to the
Before Update or Validation property for this field is preventing the
application from saving the data in the field."

I've removed almost everything from my access project. No tables. One
form containing a listbox and a textbox. The Before Update, Validation
Rule and Validation Text properties are all blank for both controls.
Here is all the code in the form:

Private Sub ListBox1_Click()
TextBox1.SetFocus
TextBox1.Text = "abc" 'this is where I get the error
End Sub

I am very confused as to what is happening. For one thing my "unbound"
listbox is displaying rows of data despite the fact that I have not
populated it. It's displaying data from previous versions of my
project. Why is this?

I also don't understand why these controls seem to be acting as though
they are bound, why are they hitting a before update event if they are
unbound? Why is it trying to "save" the data if it's unbound? Am I not
"unbinding" the controls correctly? Do I need to set some property of
the form or control to make it unbound maybe?
 
Change the code to this

Private Sub ListBox1_Click()
Me.TextBox1 = "abc"
End Sub

You do not use the .text property of a textbox to set the value of a
textbox.
You use the .text property to read the value of the textbox when the textbox
has focus.

The before update event will run for unbound textboxes.
It is a way to check that acceptable data is entered into the textbox.
If the textbox was for a date, you wouldn't want to accept someone's first
name instead of a date.
Similarly if the textbox was for a number but not text.
The before update of the textbox does not 'save' the data, it is simply
available to check for acceptable data entered.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
Change the code to this

Private Sub ListBox1_Click()
    Me.TextBox1 = "abc"
End Sub

You do not use the .text property of a textbox to set the value of a
textbox.
You use the .text property to read the value of the textbox when the textbox
has focus.

Thanks! That worked. I noticed that it also worked for TextBox1.Value.
That leads me to believe that the Value property is the default
property for the control. Since it it usually considered better
programming practice to specify the property I'm going to use .Value
and see if that works.
 
You wrote:
<Since it it usually considered better
programming practice to specify the property I'm going to use .Value
and see if that works.>

When programming in vba in access, the standard practice is to leave out the
..Value, simply because it is the default property.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Change the code to this

Private Sub ListBox1_Click()
Me.TextBox1 = "abc"
End Sub

You do not use the .text property of a textbox to set the value of a
textbox.
You use the .text property to read the value of the textbox when the
textbox
has focus.

Thanks! That worked. I noticed that it also worked for TextBox1.Value.
That leads me to believe that the Value property is the default
property for the control. Since it it usually considered better
programming practice to specify the property I'm going to use .Value
and see if that works.
 
Back
Top