'can't move focus to control ...'

J

Jonathan Leonard

'can't reference a property or method unless the control has focus'

these two errors in combination with one another are making things very
difficult (or impossible). i have a textbox whose default value which i
assume is the value property doesn't update on the onChange event. however,
it's text property does. so, i want to read the text property value.
problem with that is the control must have focus. problem with that is the
'can't move focus to control' error. can anybody help?

much thanks to anyone who knows just the right combination of quirk
workarounds here.
 
T

tina

the DefaultValue property and the Value property are not the same thing.
suggest you read up on the topics in Help, and post again if you need
further assistance.

hth
 
K

Ken Snell

In order for the OnChange event to occur, the control that is being changed
must have the focus. Programmatically changing the value of that control
does not cause the event to occur. Thus, I'm confused by what you're trying
to do here.

Please provide more specific details so that we can identify a solution for
you.
 
J

Jonathan Leonard

Ken Snell said:
In order for the OnChange event to occur, the control that is being changed
must have the focus. Programmatically changing the value of that control
does not cause the event to occur. Thus, I'm confused by what you're trying
to do here.

Please provide more specific details so that we can identify a solution for
you.

i apologize for the misunderstanding. it is not from the onChange
event that i'm trying to read the value of .text or the control would have
focus and that would work properly. but, it is the behaviour of the default
value in relation to the onChange event (that is, it doesn't update between
events even though the user is typing things and the .text property is
changing) which
forces me to use a non-default property (that is, the text property) in a
function that is called from both the textbox's onChange event and from the
form's afterUpdate event.
 
J

Jonathan Leonard

the DefaultValue property and the Value property are not the same thing.
suggest you read up on the topics in Help, and post again if you need
further assistance.

sorry, tina. i'm not referring to the DefaultValue property, but rather the
default property for that control (which happens to be 'value' if i'm not
mistaken). the problem is that in vba, when you use any property that is
not the default property (either read or write), then that control must have
focus. however, i get the error 'can't move focus to control..' when i try
to setFocus to it.
 
K

Ken Snell

You are correct that the .Value property does not change while the displayed
value is being changed -- the .Text property changes during this time. The
..Value property changes before the BeforeUpdate event occurs.

But I still ask the question from before. How are you changing the value
displayed in the control unless it already has the focus? You need to give
us more information about what you're trying to do here so that we might
help identify a solution.
 
T

tina

ah, value as default property, yes that's correct, my misunderstanding.

the problem is that in vba, when you use any property that is
not the default property (either read or write), then that control must have
focus.

i'd say that's not correct, but i may again be misunderstanding your
meaning. in any case, you've established a dialogue with Ken Snell. as an
MVP, he is a better resource for you than i am, so i will butt out of this
thread so you can work with him uninterrupted. :)
 
J

Jonathan Leonard

You are correct that the .Value property does not change while the
displayed
value is being changed -- the .Text property changes during this time. The
.Value property changes before the BeforeUpdate event occurs.
But I still ask the question from before. How are you changing the value
displayed in the control unless it already has the focus? You need to give
us more information about what you're trying to do here so that we might
help identify a solution.

The control's value is being changed by the user typing information.
However, I have a function that is called from both the OnChange event
handler of each control and also from the Form_AfterUpdate which needs to
read the .Text values of each control and update the database. Hope that
makes it clear.

Please keep in mind that these controls are not bound to anything. That's
why I'm having to write this code. A portion of my controls is bound and a
portion is not bound. I don't know if BeforeUpdate is even called for an
unbound control. I'll do some testing to see about that. If it turns out
to be called, I could just move my OnChange event handling code to the
BeforeUpdate event handler for the unbound controls. Thanks much for your
help thus far!

Jonathan
 
K

Ken Snell

BeforeUpdate and AfterUpdate events both occur for bound and unbound
controls. When they occur depends upon the type of control -- for example, a
combo box or list box "click" will trigger both events, while just typing in
a textbox will not trigger them until you try to leave the textbox.
 

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