A2000 error "Can't access this property if control does not have focus"

  • Thread starter Thread starter Mr. Me
  • Start date Start date
M

Mr. Me

I have a text box. When my form opens, in the Form_Activate I init all my
text boxes to blank, like this:
text1.text=""

But each time I do I get an error "Cannot access this property if control
does not have the focus."

Did I init my fields in the wrong event?
Should I have put the init statements in the Form_Open instead?
How do I init my text boxes (and combo boxes) once when the form loads
without getting this error?

Thanks.
 
Drop the .Text bit.

Unlike pure VB, in Access the default property of a text box is not .Text,
but .Value.

BTW, you may also want to set the value to Null, rather than a zero-length
string, i.e.:
Me.Text1 = Null

You would not normally need to do this when loading a form: text boxes
default to Null. And you would probably not want to do this in the Activate
event of a form: if another form became active for a bit, when you activate
your original one again, you would lose all your values.
 
Mr. Me said:
I have a text box. When my form opens, in the Form_Activate I init all my
text boxes to blank, like this:
text1.text=""

But each time I do I get an error "Cannot access this property if control
does not have the focus."

Did I init my fields in the wrong event?
Should I have put the init statements in the Form_Open instead?
How do I init my text boxes (and combo boxes) once when the form loads
without getting this error?

Thanks.
browsers.

Don't refer to the text property. Do this:

Me!text1 = ""

instead of this:

Me!text1.text = ""

Incidentally, why do you want to do this? If the form opens at a new record
(e.g. because it's DataEntry property is set to True) then the controls will
all be blank anyway. If it opens at an existing record, then doing this
will destroy the record!
 
browsers.

Don't refer to the text property. Do this:

Me!text1 = ""

instead of this:

Me!text1.text = ""

Incidentally, why do you want to do this? If the form opens at a new record
(e.g. because it's DataEntry property is set to True) then the controls will
all be blank anyway. If it opens at an existing record, then doing this
will destroy the record!

This form is not a bound form. It is not bound to a table and the text boxes
are not bound to fields. Thus I was concerned that when the form opened, all
the text boxes would have their default text, which is "Text1".

Thanks for the help!
 
(e-mail address removed)1net.CAPScom spoke thusly...

This form is not a bound form. It is not bound to a table and the text boxes
are not bound to fields. Thus I was concerned that when the form opened, all
the text boxes would have their default text, which is "Text1".

Thanks for the help!
browsers.

Access text boxes don't have a default value of "Text1", or indeed anything.
Text boxes on an unbound form are blank!
 
(e-mail address removed)1net.CAPScom spoke thusly...

Then I must be thinking of Visual Basic.
browsers.

Yes, you could be. But even in Visual Basic, you can remove the default
text in the properties window at design time.
 
Back
Top