473,498 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange report error message - control must have focus

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
12 2034
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
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
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
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
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
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
Thanks for the explanation
--
Smartin
Nov 13 '05 #8
Thank you for the explanation.
--
Smartin
Nov 13 '05 #9
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1767
by: WindAndWaves | last post by:
Hi Gurus The page below has a strange error. It seems to be working very well, just when you enter 8 or 9 for day, month or year then you get an error. I really have no idea where that is...
3
6386
by: Lore Leuneog | last post by:
Hello Which command do I've to use to set the focus on a control placed on a report in Design-View. Ctrl.SetFocus and Cmd.GoToControl don't work for a report. The aim is to copy the control...
1
2634
by: intl04 | last post by:
I am getting strange print-related error messages when trying to create (not print!) reports. For example, when I click 'new' to create a report then choose 'design view', I get an error message...
9
3054
by: Colin McGuire | last post by:
Hi, I have an report in Microsoft Access and it displays everything in the table. One column called "DECISION" in the table has either 1,2, or 3 in it. On my report it displays 1, 2, or 3. I want...
1
2025
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers...
7
1430
by: ChrisM | last post by:
I posted this last week, so apologies for re-posting but I'm still looking for a sensible answer, and I'm hoping somone new might be able to cast some light... Basically, I have a fairly...
7
1549
by: saurabh | last post by:
Hey, I have a form in which there are say 10 fields. I am using validator control for all the fields. suppose user forgets to fill field no. 5, 8 , 9 and 10. So on clicking the save...
5
3097
by: Ian | last post by:
Hi everyone, I have found some bizarre (to me...!) behaviour of the Form_Activate function. I have a form which has a button control used to close the form and a subform with a datasheet view...
3
1337
salimudheen
by: salimudheen | last post by:
While i try to open the report from my system is okey. But in network system it displays the error message "You can't disable a control while it has focus". But actually i never focus any control....
0
7121
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7162
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7197
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4584
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.