MS Access Form - Runtime error 2135

I have a VBA project and I want one of the text boxes on the form
to become zero when the user clicks a certain command button.

But, I am getting...
Run-timer error 2135
This property is read-only and cannot be set

But when I look at that text box's properties
Enabled = Yes, Locked = No

The code I have is in the OnClick event...
chkboxPaid.Value=True
Text54.SetFocus
Text54.Text="0"

Open in new window

--TripWire--Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Connect With a Mentor Database ArchitectCommented:
That's not exactly what you had ... you had [Paid] ... I'm using the control name.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Try this

chkboxPaid.Value=True
Text54.SetFocus
Text54 ="0"
0
 
GugroCommented:
what is the ControlSource for the textfield ??
And you should use Text54 = "0"
as the property .Text  is only accessible when you are editing the TextBox
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Connect With a Mentor Database ArchitectCommented:
Are you *sure* that text box does not have a calculated Control Source ... like

=<SomeExpression>

?

what you have should be working ...

mx
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Connect With a Mentor Database ArchitectCommented:
"Text  is only accessible when you are editing the TextBox"
Not really the case.


From Help:
Text Property
You can use the Text property to set or return the text contained in a text box or in the text box portion of a combo box. Read/write String.


mx


0
 
--TripWire--Author Commented:
Thanks
I tried Text54=0 but problem still persists.

The control source of the txtbox is...
=IIf([Insurance] = "X", ([Total]-(0.15*[Total])-[Payment], ([Total]-[Payment]))

Open in new window

0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Connect With a Mentor Database ArchitectCommented:
"The control source of the txtbox is..."
That is your problem.  You cannot set a value from Code when there is a calculated expression in the Control Source. .... sorry.

mx
0
 
--TripWire--Author Commented:
Ok thanks.  Good to know.
Can you suggest some other way to get that figure to zero?  I tried a nested IIf, but it does nothing.

=IIf([Paid]="Yes", 0, IIf(....etc...))
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Under what condition is it supposed to be Zero ?

mx
0
 
--TripWire--Author Commented:
It's the user's choice.
The way I have it now is they click a command button, which sets a yes/no box to true.
And from now on, whenever the DB see's that Paid=true, the remaining balance goes to 0.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Connect With a Mentor Database ArchitectCommented:
Maybe this:

=IIf([chkboxPaid] = True, 0, IIf([Insurance] = "X", ([Total] - (0.15 * [Total])) - [Payment], ([Total] - [Payment])))
0
 
--TripWire--Author Commented:
That's what I have.  Does nothing so far.
0
 
--TripWire--Author Commented:
Nevermind, I had quotes around Yes.
Thanks - problem solved.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Cool.

thx.mx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.