Setting Report label caption from VB6

R

Robert Trout

I have a VB 6 application that uses automation to open an Access report,
modify a label's caption on the report, and then export the report.

All works fine but for modifying the label's caption on the report from VB
6. The exported report appears as if the label's caption was never changed.
However, stepping through the VB 6 code and inspecting the access report,
the caption is changed appropriately.

The VB 6 code used to change the caption follows:

Dim objAccess as Access.Application
Dim objReport As Access.Report
Dim ctlLabel As Access.Label

' Start access
Set objAccess = New Access.Application
' Open report in design view to change label caption
objAccess.DoCmd.OpenReport "TestReport", acViewDesign
' Get a reference to the open report
Set objReport = objAccess.Reports.Item("TestReport")
' Get the label whose caption is to be changed
Set ctlLabel = objReport.Controls("Vessel")
' Change the caption
ctlLabel.Caption = "Test Name"

Why does this code not change the label's caption as evidenced by the
exported report not having the "Test Name" caption?

Thanks for your help.

Robert
 
F

fredg

I have a VB 6 application that uses automation to open an Access report,
modify a label's caption on the report, and then export the report.

All works fine but for modifying the label's caption on the report from VB
6. The exported report appears as if the label's caption was never changed.
However, stepping through the VB 6 code and inspecting the access report,
the caption is changed appropriately.

The VB 6 code used to change the caption follows:

Dim objAccess as Access.Application
Dim objReport As Access.Report
Dim ctlLabel As Access.Label

' Start access
Set objAccess = New Access.Application
' Open report in design view to change label caption
objAccess.DoCmd.OpenReport "TestReport", acViewDesign
' Get a reference to the open report
Set objReport = objAccess.Reports.Item("TestReport")
' Get the label whose caption is to be changed
Set ctlLabel = objReport.Controls("Vessel")
' Change the caption
ctlLabel.Caption = "Test Name"

Why does this code not change the label's caption as evidenced by the
exported report not having the "Test Name" caption?

Thanks for your help.

Robert

You've changed the label caption in Design View, however nowhere in
your code (so far) have you saved the change.

Add:

DoCmd.Close acReport, "TestReport", acSaveYes

Then open the report in preview. The new caption should appear.
 
R

Robert Trout

Thanks for your quick response and suggestion, Fred.

I should have included more of my code. I do close and save the report
after modifying the label.

Here is a more complete version of the VB 6 code:

Dim objAccess as Access.Application
Dim objReport As Access.Report
Dim ctlLabel As Access.Label

' Start access
Set objAccess = New Access.Application
' Open report in design view to change label caption
objAccess.DoCmd.OpenReport "TestReport", acViewDesign
' Get a reference to the open report
Set objReport = objAccess.Reports.Item("TestReport")
' Get the label whose caption is to be changed
Set ctlLabel = objReport.Controls("Vessel")
' Change the caption
ctlLabel.Caption = "Test Name"
' Close and save the report changes
objAccess.DoCmd.Close acReport, "TestReport", acSaveYes
' Export the report as HTML
objAccess.DoCmd.OutputTo acOutputReport, "TestReport", acFormatHTML,
"TestReport.html"

When I check the output HTML or open the report in preview (or design view),
the label's caption remains unchanged.

Is this a VB 6 limitation? What am I doing wrong?

Thanks for your response.

Robert
 

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