Changing a report caption at runtime

K

Kevin Sellers

I am looking for a method to change a report caption (at runtime). I have a
lab information system designed for a pathology lab and would like the
report display window to display the case number rather than a generic case
report caption. I know that this involves changing the caption property of
the report to the specific value I want displayed, but have been unable to
use vba to affect the change. I have tries using the allreports collection
to change the caption property of the report that I want to display, and I
have tried to use the on activation event to affect the caption change. Each
time I run the code, I receive an error with the description cannot change
the property of a control unless it has focus. Since the caption property is
not related to any control but the is related to the report object itself, I
see no way to use SetFocus to affect the caption property change. Any
suggestions would be greatly appreciated.

Kevin Sellers
 
M

Marshall Barton

Kevin said:
I am looking for a method to change a report caption (at runtime). I have a
lab information system designed for a pathology lab and would like the
report display window to display the case number rather than a generic case
report caption. I know that this involves changing the caption property of
the report to the specific value I want displayed, but have been unable to
use vba to affect the change. I have tries using the allreports collection
to change the caption property of the report that I want to display, and I
have tried to use the on activation event to affect the caption change. Each
time I run the code, I receive an error with the description cannot change
the property of a control unless it has focus. Since the caption property is
not related to any control but the is related to the report object itself, I
see no way to use SetFocus to affect the caption property change. Any
suggestions would be greatly appreciated.

That message implies that you're trying to assign something
to some control's Text property. If so, then you should be
using the Value property instead.

Using this line of code in the either the report's Open
event or the report header section's Format event worked for
me:
Me.Caption = "This is a test"
 
S

SA

Kevin:

In the OnActivate Event, add code like: Me.Caption = "Your Caption Text"

If you need to set this code from an external source, then create a new
property for the report in the report's module by typing:

Public Property Let SetCaption (ByVal strCaption as String)
Me.Caption = strCaption
End Property

Then when you open the report in preview your code would look like this:

DoCmd.OpenReport "MyReport", acViewPreview
Reports("MyReport").SetCaption = "Some Caption"

HTH
 

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