Problem in making changes within a report's Detail_Format event

J

John m

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
 
R

Rick Brandt

John said:
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"
 
K

Klatuu

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.
 
J

John Morgan

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
 

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