Run-time error '2115'

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?
 
J

Jeanette Cunningham

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
 
C

cr113

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

Jeanette Cunningham

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.
 

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