Recurring Problem - SetFocus on Textboxes

  • Thread starter Thread starter MDW
  • Start date Start date
M

MDW

I've been having this problem off-and-on, and I can't for
the life of me figure out what to do. I'm using Access
97, and one of my forms has a decent number of text box
controls - maybe 20-25. They are all unbound.

As I try to get all the values from the textboxes, I run
into a snag - I get an error that says "Microsoft Access
Could Not Move The Focus To [TextBoxName]. It may be
hidden, disabled, or of a type that cannot receive the
focus." The thing is, none of those conditions are true.
All the text boxes are perfoectly normal, unhidden
controls. It's like Access gets confused or something.

Has anyone else had this problem? What in the world causes
it? Is there some opposite version of the .SetFocus
method that I can use to remove focus from the box when
I'm done with it?

It was once suggested that I just assign variables to the
default value of the text boxes. I know that you can just
use the name of the textbox since the ".Text" property is
the default; e.g., strVariable = txtMyBox. However, that
causes problems if the user leaves the box blank...I get
an "Invalid use of null" error. Does anyone know a way
around THAT? That would be a solution to my problems.
 
Hello,

I know the following is true for Access 2000 and later and I *think* this
applies to A97 as well (apologies if it is not). If you do not specify a
property the default (.value) is applied. You can only access the .Text
property of a control when it has the focus. Otherwise, you will get the
error that you mention below. If you use .Value, check for null values
before you try and do something with the control:

If IsNull(Me.MyTextBox.Value) Then ' Should be the same as writing
Me.MyTextBox
' Textbox is null
Else
' Text box is not null
End If

Again, apologies if the .Value property was implemented in later versions of
Access but I am sure that .Value has been used from the start.

Good Luck!

Neil.
 
Neil said:
I know the following is true for Access 2000 and later and I *think* this
applies to A97 as well (apologies if it is not). If you do not specify a
property the default (.value) is applied. You can only access the .Text
property of a control when it has the focus. Otherwise, you will get the
error that you mention below. If you use .Value, check for null values
before you try and do something with the control:

If IsNull(Me.MyTextBox.Value) Then ' Should be the same as writing
Me.MyTextBox
' Textbox is null
Else
' Text box is not null
End If

Again, apologies if the .Value property was implemented in later versions of
Access but I am sure that .Value has been used from the start.


Good answer, Neil. And, yes, this is true for all versions
of Access.

This problem occurs because folks from the VB world (where
it's how things are done) are in the habit of using the Text
property. But, in Access the Text property is only used in
special circumstance and, as you explained, they should be
using the Value property so there is no need to set the
focus.
--
Marsh
MVP [MS Access]


MDW said:
I've been having this problem off-and-on, and I can't for
the life of me figure out what to do. I'm using Access
97, and one of my forms has a decent number of text box
controls - maybe 20-25. They are all unbound.

As I try to get all the values from the textboxes, I run
into a snag - I get an error that says "Microsoft Access
Could Not Move The Focus To [TextBoxName]. It may be
hidden, disabled, or of a type that cannot receive the
focus." The thing is, none of those conditions are true.
All the text boxes are perfoectly normal, unhidden
controls. It's like Access gets confused or something.

Has anyone else had this problem? What in the world causes
it? Is there some opposite version of the .SetFocus
method that I can use to remove focus from the box when
I'm done with it?

It was once suggested that I just assign variables to the
default value of the text boxes. I know that you can just
use the name of the textbox since the ".Text" property is
the default; e.g., strVariable = txtMyBox. However, that
causes problems if the user leaves the box blank...I get
an "Invalid use of null" error. Does anyone know a way
around THAT? That would be a solution to my problems.
 
MDW said:
I've been having this problem off-and-on, and I can't for
the life of me figure out what to do. I'm using Access
97, and one of my forms has a decent number of text box
controls - maybe 20-25. They are all unbound.

As I try to get all the values from the textboxes, I run
into a snag - I get an error that says "Microsoft Access
Could Not Move The Focus To [TextBoxName]. It may be
hidden, disabled, or of a type that cannot receive the
focus." The thing is, none of those conditions are true.
All the text boxes are perfoectly normal, unhidden
controls. It's like Access gets confused or something.

Has anyone else had this problem? What in the world causes
it? Is there some opposite version of the .SetFocus
method that I can use to remove focus from the box when
I'm done with it?

It was once suggested that I just assign variables to the
default value of the text boxes. I know that you can just
use the name of the textbox since the ".Text" property is
the default; e.g., strVariable = txtMyBox. However, that
causes problems if the user leaves the box blank...I get
an "Invalid use of null" error. Does anyone know a way
around THAT? That would be a solution to my problems.

I believe you'll get that message when you try to set focus
to another control from an event procedure that can not give
up the focus.

Actually, as Neil pointed out, you should be using the Value
property instead of the Text property (so there's no need to
change the focus). In Access, the Text property has a
distinctly different use from what you're used to in VB.
 
Back
Top