Set Report Value from Code

D

D. McDonough

I have created a report. I want to show a value in a text
box on this report ... this value is calculated/specified
by me in the Activate event procedure for the report.

When I try to set the value of the text box, I get the
following error (Run-tim error '2185'):

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


How can I do what I want to do?? (My sample code is below.)

Thanks!


Here's an example:

Private Sub Report_Activate()
Dim myCtrl As Control
Dim extraValue as Long

extraValue = 171717

For Each myCtrl In Me.Controls
If myCtrl.Properties("Name") = "ExtraValue" Then
myCtrl.Properties("Text") = extraValue 'errors
End If
Next
End Sub
 
R

Rick Brandt

D. McDonough said:
I have created a report. I want to show a value in a text
box on this report ... this value is calculated/specified
by me in the Activate event procedure for the report.

When I try to set the value of the text box, I get the
following error (Run-tim error '2185'):

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


How can I do what I want to do?? (My sample code is below.)

You don't want the Text property. Use the Value property instead and since that is
the default property for controls you don't even need to explicitly qualify it. Just
use the name of the control.

Also you'll need to do this in one of the Report's processing events. Either Open or
the relevent section's Format or Print event. You cannot dynamically change controls
on an open report with the Activate event.
 

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