Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem in making changes within a report's Detail_Format event

372 views
Skip to first unread message

John m

unread,
Mar 21, 2008, 9:12:33 AM3/21/08
to
I am using Access 2007 for the first time after a fair amount of use of
previous Access versions pre 2003.

I am trying to change the contents of a text box in Access 2007 at the
format event of a report using the following:

***********
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

txtWeekDay.Text = "tested"
End Sub
*************


If I do this when running print review I get the followng error message:

"You can't reference a method or property for a control unless the control
has the focus"


If I then add to the code as follows

*********
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
txtWeekDay.SetFocus
txtWeekDay.Text = "tested"
End Sub
***********

I then get the error message:

"Microsoft access does not allow you to use this method in the current view"

I suppose I am missing something obvious but I cannot see it so I would be
most grateful for advice,

Best wishes, John Morgan


Rick Brandt

unread,
Mar 21, 2008, 9:41:21 AM3/21/08
to
John m wrote:
> I am trying to change the contents of a text box in Access 2007 at the
> format event of a report using the following:
>
> Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
>
> txtWeekDay.Text = "tested"
> End Sub
>
> If I do this when running print review I get the followng error
> message:
> "You can't reference a method or property for a control unless the
> control has the focus"

Lose the dot-Text. It is rarely used in Access and you are seeing why. In
Access we use the Value property, not the Text property and since Value is
the default property you don't even need to mention it in your code...

txtWeekDay = "tested"

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com


Klatuu

unread,
Mar 21, 2008, 9:50:02 AM3/21/08
to
The Text property is more a VB property than VBA. The Text property can only
be addressed when a control has the focus.
In Access VBA, you would use the Value property, but since that is the
default property for a control, even it is not required. All you need is:

Me.txtWeekDay = "tested"

Note, it is always best to qualify your control references.
--
Dave Hargis, Microsoft Access MVP

John Morgan

unread,
Mar 21, 2008, 11:12:05 AM3/21/08
to

Thanks very much, thats got things working properly. Perhaps coming
from ASPNet back to Access VBA has lead to me using the dot notation.
I have frequently used the format event in Access 2002 and previous
versions without problem but I never used the dot notation.

I think that also solves the puzzling problem I had of being requested
to set a control focus in code behind a form.

Your help is much appreciated,

Best wishes, John Morgan

On Fri, 21 Mar 2008 13:12:33 GMT, "John m" <j...@woodlander.co.uk>
wrote:

0 new messages