By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,490 Members | 1,789 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,490 IT Pros & Developers. It's quick & easy.

Strange report error message - control must have focus

P: n/a
I have a report which prints data from a parent table and two child
tables (Contract and Kosten). Because it is a bit long, I suppress some
fields which are often empty, based on methods found in the archive for
this group: allowing can-shrink on the field itself and the following
code in the details section to suppress the label:

If (Me!InpassingWerkproces.Text = "") Then
Me!InpassingWerkproces_Bijschrift.Visible = False
Else
Me!InpassingWerkproces_Bijschrift.Visible = True
End If

The suppressed fields occur in all three records.

When there is both a Contract and Kosten record this works fine. If
there is no Kosten record this works fine. But when there is no Contract
record I get an error message (translated from the Dutch) "you can only
refer to a property or method of a control if the control has the
focus". On debugging, the code complained about is the 'if' line of the
first instance of the label-suppression code above. If I comment that
out, it complains about the next instance.

I have looked in vain for differences in the ways I handle Contract and
Kosten records.

Can anyone suggest where I should be looking?
(Access 2000, Dutch version, Windows XP Pro)

========

Subsidiary question (much less important): the examples I found in the
archive all provided only the first half of the above IF statement. But
I found that the value of the 'Visible' property was maintained from one
detail record to the next: once I set it to False, it remained False for
all subsequent records. Has the behaviour of Access changed at some
point?

--
Stephen Poley
Nov 13 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
On Sun, 30 Oct 2005 07:44:13 +0100, Stephen Poley <sb******************@xs4all.nl> wrote:
I have a report which prints data from a parent table and two child
tables (Contract and Kosten). Because it is a bit long, I suppress some
fields which are often empty, based on methods found in the archive for
this group: allowing can-shrink on the field itself and the following
code in the details section to suppress the label:

If (Me!InpassingWerkproces.Text = "") Then
Me!InpassingWerkproces_Bijschrift.Visible = False
Else
Me!InpassingWerkproces_Bijschrift.Visible = True
End If

The suppressed fields occur in all three records.

When there is both a Contract and Kosten record this works fine. If
there is no Kosten record this works fine. But when there is no Contract
record I get an error message (translated from the Dutch) "you can only
refer to a property or method of a control if the control has the
focus". On debugging, the code complained about is the 'if' line of the
first instance of the label-suppression code above. If I comment that
out, it complains about the next instance.

I have looked in vain for differences in the ways I handle Contract and
Kosten records.

Can anyone suggest where I should be looking?
(Access 2000, Dutch version, Windows XP Pro)

========

Subsidiary question (much less important): the examples I found in the
archive all provided only the first half of the above IF statement. But
I found that the value of the 'Visible' property was maintained from one
detail record to the next: once I set it to False, it remained False for
all subsequent records. Has the behaviour of Access changed at some
point?

Use -
If (Me!InpassingWerkproces= "")
instead of
If (Me!InpassingWerkproces.Text = "")

The Text property is only available if the control has focus, which never happens in a report.

Nov 13 '05 #2

P: n/a
On Sun, 30 Oct 2005 08:18:50 GMT, Wayne Gillespie
<be*****@NOhotmailSPAM.com.au> wrote:
On Sun, 30 Oct 2005 07:44:13 +0100, Stephen Poley <sb******************@xs4all.nl> wrote:
I have a report which prints data from a parent table and two child
tables (Contract and Kosten). Because it is a bit long, I suppress some
fields which are often empty: <snip> If (Me!InpassingWerkproces.Text = "") Then
Me!InpassingWerkproces_Bijschrift.Visible = False
Else
Me!InpassingWerkproces_Bijschrift.Visible = True
End If

The suppressed fields occur in all three records.

When there is both a Contract and Kosten record this works fine. If
there is no Kosten record this works fine. But when there is no Contract
record I get an error message (translated from the Dutch) "you can only
refer to a property or method of a control if the control has the
focus".
Use -
If (Me!InpassingWerkproces= "")
instead of
If (Me!InpassingWerkproces.Text = "")

The Text property is only available if the control has focus, which never happens in a report.

If that is the case, how is it that my report works fine when both child
records are present?

--
Stephen Poley
Nov 13 '05 #3

P: n/a
1. Try using the .Value property instead of .Text.
Or just use
If (Me!InpassingWerkproces = "") Then

2. The behavior you've observed (changing the formatting of a detail record
remains until changed again) has been there as long as I've been working
with Access (back to 2.0).

HTH

"Stephen Poley" <sb******************@xs4all.nl> wrote in message
news:e2********************************@4ax.com...
I have a report which prints data from a parent table and two child
tables (Contract and Kosten). Because it is a bit long, I suppress some
fields which are often empty, based on methods found in the archive for
this group: allowing can-shrink on the field itself and the following
code in the details section to suppress the label:

If (Me!InpassingWerkproces.Text = "") Then
Me!InpassingWerkproces_Bijschrift.Visible = False
Else
Me!InpassingWerkproces_Bijschrift.Visible = True
End If

The suppressed fields occur in all three records.

When there is both a Contract and Kosten record this works fine. If
there is no Kosten record this works fine. But when there is no Contract
record I get an error message (translated from the Dutch) "you can only
refer to a property or method of a control if the control has the
focus". On debugging, the code complained about is the 'if' line of the
first instance of the label-suppression code above. If I comment that
out, it complains about the next instance.

I have looked in vain for differences in the ways I handle Contract and
Kosten records.

Can anyone suggest where I should be looking?
(Access 2000, Dutch version, Windows XP Pro)

========

Subsidiary question (much less important): the examples I found in the
archive all provided only the first half of the above IF statement. But
I found that the value of the 'Visible' property was maintained from one
detail record to the next: once I set it to False, it remained False for
all subsequent records. Has the behaviour of Access changed at some
point?

--
Stephen Poley

Nov 13 '05 #4

P: n/a
Wayne Gillespie wrote:
Use -
If (Me!InpassingWerkproces= "")
instead of
If (Me!InpassingWerkproces.Text = "")

The Text property is only available if the control has focus...


I've noticed this too and have been puzzled by it. Isn't Text the
default property of a TextBox?

So other than the fact that one way works and the other does not, what
is the difference between these two statements?

txtMyText = "foo"
txtMyText.Text = "bar"

Is this some peculiarity of Access VBA?

--
Smartin
Nov 13 '05 #5

P: n/a
Smartin <sm********@yahoo.com> wrote in
news:w9********************@giganews.com:
Wayne Gillespie wrote:
Use -
If (Me!InpassingWerkproces= "")
instead of
If (Me!InpassingWerkproces.Text = "")

The Text property is only available if the control has
focus...
I've noticed this too and have been puzzled by it. Isn't Text
the default property of a TextBox?


The default value of any control that can be bound to a field is
..value. At least the rule is consistent.

The .text property contains whatever the user has typed into a
control, for editing. since it can only be edited when the
control has focus, the property is only accessible when the
control has focus.
So other than the fact that one way works and the other does
not, what is the difference between these two statements?

txtMyText = "foo"
txtMyText.Text = "bar"
txtMyText refers to the bound value,
as does txtmytext = 99

txtMyText.Text = "bar" refers to the value of txtMytext while
the field is being edited.

The use of the two properties allows one to cancel an edit, ir
to save it.
Is this some peculiarity of Access VBA?

Probably, as it's only necessary when editing a bound control.
--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #6

P: n/a
Smartin wrote:
Wayne Gillespie wrote:
Use -
If (Me!InpassingWerkproces= "")
instead of
If (Me!InpassingWerkproces.Text = "")

The Text property is only available if the control has focus...
I've noticed this too and have been puzzled by it. Isn't Text the
default property of a TextBox?


In VB yes. In Access the Value property is the default.
So other than the fact that one way works and the other does not, what
is the difference between these two statements?

txtMyText = "foo"
txtMyText.Text = "bar"

Is this some peculiarity of Access VBA?


The Text property in Access is the not yet committed text in the control as you
are editing it. That is why it is only available for the control that currently
has focus.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com

Nov 13 '05 #7

P: n/a
Thanks for the explanation
--
Smartin
Nov 13 '05 #8

P: n/a
Thank you for the explanation.
--
Smartin
Nov 13 '05 #9

P: n/a
On Sun, 30 Oct 2005 22:31:14 GMT, "MacDermott" <ma********@nospam.com>
wrote:
1. Try using the .Value property instead of .Text.
Or just use
If (Me!InpassingWerkproces = "") Then
That's actually what I started with, but it didn't work.
IsNull(Me!InpassingWerkproces) turned out to work. See my other post.
2. The behavior you've observed (changing the formatting of a detail record
remains until changed again) has been there as long as I've been working
with Access (back to 2.0).


OK, thanks. Apparently some of the code posted here that I thought was
real code must have just been air code.

--
Stephen Poley
Nov 13 '05 #10

P: n/a
On Mon, 31 Oct 2005 00:25:28 GMT, Bob Quintal <rq******@sympatico.ca>
wrote:
Smartin <sm********@yahoo.com> wrote in
news:w9********************@giganews.com:
Wayne Gillespie wrote:
Use -
If (Me!InpassingWerkproces= "")
instead of
If (Me!InpassingWerkproces.Text = "")

The Text property is only available if the control has
focus...


I've noticed this too and have been puzzled by it. Isn't Text
the default property of a TextBox?


The default value of any control that can be bound to a field is
.value. At least the rule is consistent.

The .text property contains whatever the user has typed into a
control, for editing. since it can only be edited when the
control has focus, the property is only accessible when the
control has focus.


OK, I've tried various possibilities out, in the hope that it gives
useful information to future browsers of the archive. The following
works, i.e. it suppresses labels for empty fields in my report:

If IsNull(Me!ExtraInfo) Then
Me!ExtraInfo_Bijschrift.Visible = False
Else
Me!ExtraInfo_Bijschrift.Visible = True
End If

Using IsNull(Me!ExtraInfo.Value) also works.

(Me!ExtraInfo = "") and (Me!ExtraInfo.Value = "") do not work for me. I
don't know whether one can get a zero-length string in an Access field -
I don't seem to have them, anyway.

(Me!ExtraInfo.Text = "") should not work at all in reports according to
you and Rick, yet sometimes it does - see my original post. But, as I
discovered, it's not reliable and presumably should be avoided in
reports.

I would hazard a guess that at some stage someone at Microsoft thought
it would be handy to provide Text as a synonym to Value in reports, for
people who are used to VB. But if so, the idea was never carried through
consistently (and it seems a pretty bad idea to me anyway).

--
Stephen Poley
Nov 13 '05 #11

P: n/a
On Mon, 31 Oct 2005 19:51:20 +0100, Stephen Poley <sb******************@xs4all.nl> wrote:

OK, I've tried various possibilities out, in the hope that it gives
useful information to future browsers of the archive. The following
works, i.e. it suppresses labels for empty fields in my report:

If IsNull(Me!ExtraInfo) Then
Me!ExtraInfo_Bijschrift.Visible = False
Else
Me!ExtraInfo_Bijschrift.Visible = True
End If

Using IsNull(Me!ExtraInfo.Value) also works.

(Me!ExtraInfo = "") and (Me!ExtraInfo.Value = "") do not work for me. I
don't know whether one can get a zero-length string in an Access field -
I don't seem to have them, anyway.

(Me!ExtraInfo.Text = "") should not work at all in reports according to
you and Rick, yet sometimes it does - see my original post. But, as I
discovered, it's not reliable and presumably should be avoided in
reports.

I would hazard a guess that at some stage someone at Microsoft thought
it would be handy to provide Text as a synonym to Value in reports, for
people who are used to VB. But if so, the idea was never carried through
consistently (and it seems a pretty bad idea to me anyway).


You can also test for Nulls and Zero-Length Strings together by using -

If Len(Me!ExtraInfo & vbNullString)=0

This is handy if the Allow Zero Length String property of the table is set to Yes, and the table could contain a mix of
either Nulls or ZLS's.

Nov 13 '05 #12

P: n/a
On Tue, 01 Nov 2005 02:59:42 GMT, Wayne Gillespie
<be*****@NOhotmailSPAM.com.au> wrote:

You can also test for Nulls and Zero-Length Strings together by using -

If Len(Me!ExtraInfo & vbNullString)=0

This is handy if the Allow Zero Length String property of the table is set to Yes, and the table could contain a mix of
either Nulls or ZLS's.


Thanks.

--
Stephen Poley
Nov 13 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.