beginner 2185 error & focus

G

Guest

Hi all,

Am used to Visual.net where one can write to a text box on the form with:

Me.BoxCount1.Text = "Box Count is 14 blah blah blah"

(where BoxCount1 is a text box or label)

but when I set this up in programming the code in a Private Sub of a button
click in Access it returns:
Error 2185 : Can not reference a Property or Method for a control unless the
control has the focus.

The button click kicks off a variety of calcs and I want to write a variety
of results to various unbound textboxes on the form....such as BoxCount1.
Code works ok - just not sure how one sends the result back as basic text
messages to the Form in regard to this focus issue.

Would appreciate some advice on this method....thnx...
 
A

Allen Browne

Drop the ".Text" bit.

Access is a data-centric program, so the default property of a text box is
Value, not Text.

When you are entering something into a text box, the Text property returns
what is currently in the field. For example, if you are part way through
entering a date, the Text might be:
1/2/
But that could never be accepted as the Value of the text box if it is bound
to a Date/Time field. Access performs that validation, and generates an
engine-level error if the Text cannot become the Value.

As a result, the Text property applies only to the control that has focus,
which is different from classic VB or VB.NET. In Access you use:
Me.BoxCount1 = "Box Count is 14 blah blah blah"
which is a shorthand for:
Me.BoxCount1.Value = "Box Count is 14 blah blah blah"
 
G

Guest

ok thanks -

Before getting your input here I had discovered that if I precede with:

Me.BoxCount1.SetFocus

then this does work
Me.BoxCount1.Text = "Box Count is 14 blah blah"

Originally I could not get your advice to work in terms of:
Me.BoxCount1 = "Box Count is 14 blah blah"

and then I experimentally added on the .text based on my VB.........however
I should add that also at the same time I was doing this within the framework
of an If/Then and I found that writing to the textbox did not work when my
previous statement(s) was within the If/Then - - but did work if I moved
them outside of the If/Then.

So I'm sure your advice works - it may be that when I was trying it at first
I was still inside the If/Then at the time and since it would not work I then
tagged on the .text - add the preceding SetFocus statement - - it still did
not work - and then moved it outside the If/Then and it did work - - - and
after all that I never went back and experimented without the .text (when it
works it works....)

Which does kind of raise an issue in my mind compared to Visual as to why
one can not write to a textbox from within the If/Then with Access as that is
very useful.

Much Appreciated.
 
A

Allen Browne

Experiment.

You can write a value to a text box inside an If block in code.

Don't forget that you are also dealing with the field in the form's
RecordSource as well as the control (e.g. text box) on the form, which may
have the same name.
 
G

Guest

yeah - major brain freeze - it works fine inside the If/Then - - not sure
what I was thinking before.......
 

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