Setting Report Text Box ControlSource Programatically

E

ExcelMan

I'm having trouble setting a text box controlsource on a report during
the Report_Open event.

Whenever I use the syntax

Me.txtMyTextBox.ControlSource = "=SomeText" & strVariable

if the value of strVariable looks like a number, (e.g. 2005) I have no
problem. But if it looks like a text string, when the report runs it
requests the value of a parameter (named strVariable). This even
happens if I replace strVariable with "Some more text".

What's going on. How can I pass a variable that contains text into the
controlsource so I can have it populate the textbox on my report?

Note: I'm trying to create a subheading that includes some text and
values I pulled from the database when opening the report. E.g.
"Actual data through Jan 2005"

Thanks.
 
T

Terry

Hi,

Rather than setting the control source.

(off the top of my head)

dim stuff as string
dim MoreStuff as string
stuff = "some data "
MoreStuff = "some more data"
Me.YourTextBox = stuff & MoreStuff

This sets the contents of the control rather than the
control source.

HTH

Terry
 
M

Marshall Barton

ExcelMan said:
I'm having trouble setting a text box controlsource on a report during
the Report_Open event.

Whenever I use the syntax

Me.txtMyTextBox.ControlSource = "=SomeText" & strVariable

if the value of strVariable looks like a number, (e.g. 2005) I have no
problem. But if it looks like a text string, when the report runs it
requests the value of a parameter (named strVariable). This even
happens if I replace strVariable with "Some more text".

What's going on. How can I pass a variable that contains text into the
controlsource so I can have it populate the textbox on my report?

Note: I'm trying to create a subheading that includes some text and
values I pulled from the database when opening the report. E.g.
"Actual data through Jan 2005"


If strVariable is a FIELD in the report's Record Source
table/query, the starement is missing quotes around the text
portion:
txtMyTextBox.ControlSource = "=""SomeText"" & strVariable"

If strVariable is a VBA varible in the report's module, then
you should use Terry's code in the text box section's Format
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