|
|
I am trying to set the text property of a textbox in order to trigger a Change() event on it (Access 2003). The textbox is enabled, not locked, visible, and unbound. I set focus to it before trying to change the text property. Why is this giving me an error 2135, "This property is read-only and can't be set"? The docs say Text is a read/write property.
Me.txtCount.SetFocus Me.txtCount.Text = Cstr(ntot) ' ntot is Long
The current Value of Me.txtCount is "". I can change Me.txtCount.Value, but of course this doesn't trigger the Change() event.
Any help greatly appreciated.
|
|
Nevermind - answered my own question. You can't set the Text property on a control (and probably many other properties) when you're still at the Load event. Hopefully this may be useful to others. I did what I needed to do a different way.
"ericgj" wrote:
[Quoted Text] > I am trying to set the text property of a textbox in order to trigger a > Change() event on it (Access 2003). The textbox is enabled, not locked, > visible, and unbound. I set focus to it before trying to change the text > property. Why is this giving me an error 2135, "This property is read-only > and can't be set"? The docs say Text is a read/write property. > > Me.txtCount.SetFocus > Me.txtCount.Text = Cstr(ntot) ' ntot is Long > > The current Value of Me.txtCount is "". I can change Me.txtCount.Value, but > of course this doesn't trigger the Change() event. > > Any help greatly appreciated. >
|
|
Don't know what to tell you! I set up a form as per your post, copied and pasted your code straight in, placing it behind a command button, and it ran as expected. How are you triggering this event, i.e. where doe the code
[Quoted Text] >Me.txtCount.SetFocus >Me.txtCount.Text = Cstr(ntot) ' ntot is Long
reside?
I'm running v2003/SP2. What service pack are you runnng? If SP3, do you have the hotfix installed?
You might try deleting the textbox and re-creating it.
-- There's ALWAYS more than one way to skin a cat!
Answers/posts based on Access 2000/2003
Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200811/1
|
|
On Mon, 17 Nov 2008 09:59:01 -0800, ericgj <ericgj[ at ]discussions.microsoft.com> wrote:
[Quoted Text] >Nevermind - answered my own question. You can't set the Text property on a >control (and probably many other properties) when you're still at the Load >event. >Hopefully this may be useful to others. I did what I needed to do a >different way.
The Text property *is* read/write - but only when the control has the focus. This differs from Visual Basic's convention! What you can do is to set the control's Value property; that is the default property so you can omit the ..value keyword if you wish and just use
Me!controlname = <whatever>
--
John W. Vinson [MVP]
|
|
=?Utf-8?B?ZXJpY2dq?= <ericgj[ at ]discussions.microsoft.com> wrote in news:EC1F408A-F676-4E4F-AF13-3BCE79487703[ at ]microsoft.com:
[Quoted Text] > You can't set the Text property on a > control (and probably many other properties) when you're still at > the Load event.
Actually, it may be that the reason for this is that the control can't really get the focus yet during the OnLoad event. You should be able to just set the control's value in the OnLoad (or set the value of the field in the underlying recordsource, which is already available during the OnLoad event).
Also, I'm pretty sure you can't trigger the OnChange event of controls in code -- only typing triggers that event (or, I guess, pasting a value into the control).
-- David W. Fenton http://www.dfenton.com/ usenet at dfenton dot com http://www.dfenton.com/DFA/
|
|
John or David, could one of you explain to me why responses on this site get posted in such a haphazard way? When my first response was posted, at 11-17- 2008 13:10, the OP's post of 11-17-2008 12:59 wasn't visible to me, which is why I asked him ***where*** his code was placed. It's very confusing trying to follow the flow of a thread, with questions being asked that ***appear*** to have already been answered.
-- There's ALWAYS more than one way to skin a cat!
Answers/posts based on Access 2000/2003
Message posted via http://www.accessmonster.com
|
|
On Wed, 19 Nov 2008 05:06:13 GMT, "Linq Adams via AccessMonster.com" <u28780[ at ]uwe> wrote:
[Quoted Text] >John or David, could one of you explain to me why responses on this site get >posted in such a haphazard way? When my first response was posted, at 11-17- >2008 13:10, the OP's post of 11-17-2008 12:59 wasn't visible to me, which is >why I asked him ***where*** his code was placed. It's very confusing trying >to follow the flow of a thread, with questions being asked that ***appear*** >to have already been answered.
Well, I see in your .sig
Message posted via http://www.accessmonster.com
Accessmonster is one of many "repackagers" who take the USENET newsgroups microsoft.public.access.* and display them through a user interface. Ask the middleman why the posts are coming out of order.
It is worth noting that Usenet has always been chaotic in terms of time of posting - and times of propagation from one server to another. --
John W. Vinson [MVP]
|
|
Thanks for the info, John!
-- There's ALWAYS more than one way to skin a cat!
Answers/posts based on Access 2000/2003
Message posted via http://www.accessmonster.com
|
|
|