Unable to set value to text control in a form

  • Thread starter Thread starter spavithr
  • Start date Start date
S

spavithr

I have an unbound test control called as "prd_id" in my
form. I wrote the following code to set the value to it in
the form_open event,

me![prd_id].text = rs![prd_id]

It gave an error saying "cannot access a control's value
without setting focus to it"

So i had to change the code as

me![prd_id].setfocus
me![prd_id].text = rs![prd_id]

this worked fine. But i feel there should be a way to set
the value without setting the focus. Otherwise when I have
a lot of controls to access, I will have to set the focus
for all of them.

Please advise.

Thanks
 
This is a common point of confusion for VB programmers who are starting to
use Access. In Access you do not use the Text Property to set the value of a
control - instead you use the value property. Since the value property is
the default property of the control you don't even have to explicitly refer
to it. Soo instead of your expression, try the following:

me![prd_id] = rs![prd_id]

or

me![prd_id].value = rs![prd_id]

The text property is used to hold the value that is typed into a control
before it is saved to the control - that is why the control must have focus
in order to use the Text property.
 
Back
Top