Connecting Tech Pros Worldwide Forums | Help | Site Map

CreateReport(, templateName) not coping report properly

jess@askey.org
Guest
 
Posts: n/a
#1: Nov 13 '05
Hi,

Im using the following code to make a new report based on an existing
report.

Set rpt = CreateReport(, "_SemiAnnualMaster")

The problem that I am running into is that none of the report controls
are coming across. All I end up with is a blank report. So, I manually
copied all the Labels, Text boxes etc across..

Dim ctl As Access.Control
Dim ctlNewLabel As Access.Label
Dim ctlNewtextBox As Access.TextBox
Dim ctlNewLine As Access.Line

For Each ctl In rptMaster.Controls
Select Case ctl.Properties("ControlType")
Case Access.acLabel:
Set ctlLabel = ctl
Set ctlNewLabel = CreateReportControl(rpt.Name,
acLabel, ctlLabel.Section, , , ctlLabel.Left, ctlLabel.Top,
ctlLabel.Width, ctlLabel.Height)
ctlNewLabel.Name = ctlLabel.Name
ctlNewLabel.Caption = ctlLabel.Caption
ctlNewLabel.TextAlign = ctlLabel.TextAlign
Case Access.acTextBox:
Set ctlTextBox = ctl
Set ctlNewtextBox = CreateReportControl(rpt.Name,
acTextBox, ctlTextBox.Section, , ctlTextBox.ControlSource,
ctlTextBox.Left, ctlTextBox.Top, ctlTextBox.Width, ctlTextBox.Height)
ctlNewtextBox.Name = ctlTextBox.Name
ctlNewtextBox.TextAlign = ctlTextBox.TextAlign
'ctlNewtextBox.DefaultValue = ctlTextBox.DefaultValue
Case Access.acLine:
Set ctlLine = ctl
Set ctlNewLine = CreateReportControl(rpt.Name, acLine,
ctlLine.Section, , , ctlLine.Left, ctlLine.Top, ctlLine.Width,
ctlLine.Height)
ctlNewLine.Name = ctlLine.Name
Case Else

End Select

Next ctl

DoCmd.Close acReport, "_SemiAnnualMaster", acSaveNo

After this, the issue Im running into is that none of the templates
grouping colums are in the new report. Before I start trying to copy
the grouping via code, I seem to be thinking that the usefulness of
CreateReport is very small unless I am missing something. I thought
that this may be an issue with the recordsource of the template being
broken because I can see how that may effect controls. Unfortunately,
even my non-databound controls are not being created with CreateReport.
I set recordsource correctly in the template report and I still get an
empty report upon using CreateReport specifying that template name.

Are there any reason's why I might get an empty report using
CreateReport that anyone knows of or is CreateReport totally useless?
;-) Should I examine my rowsource more closely perhaps? CreateReport( ,
templateName) seemed like it would be so useful if I could get it
working.

thank you


Stephen Lebans
Guest
 
Posts: n/a
#2: Nov 13 '05

re: CreateReport(, templateName) not coping report properly


I know that Access does not like the underscore character for object naming
purposes. Have you tried removing the underscrore char from your sample
code? Normally we would simply enclose any object name containing a leading
underscore char within square barackets[ ] but that would not work here.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
<jess@askey.org> wrote in message
news:1127162242.928209.68120@f14g2000cwb.googlegro ups.com...[color=blue]
> Hi,
>
> Im using the following code to make a new report based on an existing
> report.
>
> Set rpt = CreateReport(, "_SemiAnnualMaster")
>
> The problem that I am running into is that none of the report controls
> are coming across. All I end up with is a blank report. So, I manually
> copied all the Labels, Text boxes etc across..
>
> Dim ctl As Access.Control
> Dim ctlNewLabel As Access.Label
> Dim ctlNewtextBox As Access.TextBox
> Dim ctlNewLine As Access.Line
>
> For Each ctl In rptMaster.Controls
> Select Case ctl.Properties("ControlType")
> Case Access.acLabel:
> Set ctlLabel = ctl
> Set ctlNewLabel = CreateReportControl(rpt.Name,
> acLabel, ctlLabel.Section, , , ctlLabel.Left, ctlLabel.Top,
> ctlLabel.Width, ctlLabel.Height)
> ctlNewLabel.Name = ctlLabel.Name
> ctlNewLabel.Caption = ctlLabel.Caption
> ctlNewLabel.TextAlign = ctlLabel.TextAlign
> Case Access.acTextBox:
> Set ctlTextBox = ctl
> Set ctlNewtextBox = CreateReportControl(rpt.Name,
> acTextBox, ctlTextBox.Section, , ctlTextBox.ControlSource,
> ctlTextBox.Left, ctlTextBox.Top, ctlTextBox.Width, ctlTextBox.Height)
> ctlNewtextBox.Name = ctlTextBox.Name
> ctlNewtextBox.TextAlign = ctlTextBox.TextAlign
> 'ctlNewtextBox.DefaultValue = ctlTextBox.DefaultValue
> Case Access.acLine:
> Set ctlLine = ctl
> Set ctlNewLine = CreateReportControl(rpt.Name, acLine,
> ctlLine.Section, , , ctlLine.Left, ctlLine.Top, ctlLine.Width,
> ctlLine.Height)
> ctlNewLine.Name = ctlLine.Name
> Case Else
>
> End Select
>
> Next ctl
>
> DoCmd.Close acReport, "_SemiAnnualMaster", acSaveNo
>
> After this, the issue Im running into is that none of the templates
> grouping colums are in the new report. Before I start trying to copy
> the grouping via code, I seem to be thinking that the usefulness of
> CreateReport is very small unless I am missing something. I thought
> that this may be an issue with the recordsource of the template being
> broken because I can see how that may effect controls. Unfortunately,
> even my non-databound controls are not being created with CreateReport.
> I set recordsource correctly in the template report and I still get an
> empty report upon using CreateReport specifying that template name.
>
> Are there any reason's why I might get an empty report using
> CreateReport that anyone knows of or is CreateReport totally useless?
> ;-) Should I examine my rowsource more closely perhaps? CreateReport( ,
> templateName) seemed like it would be so useful if I could get it
> working.
>
> thank you
>[/color]


jess@askey.org
Guest
 
Posts: n/a
#3: Nov 13 '05

re: CreateReport(, templateName) not coping report properly


I ended up finding a different way around the issue of creating a new
report based on another existing report... this brought everything
across exactly as the template report..

On Error Resume Next
'Delete if it already exists...
DoCmd.DeleteObject acReport, "_MyNewReport"
On Error GoTo 0

DoCmd.CopyObject , "_MyNewReport", acReport, "_MyTemplate"

I will try removing the underscores and see if that helps. I did wonder
about the underscore also because I was not able to access the report
using the fully qualified name...

Reports__MyTemplate.Controls

So, a good rule of thumb is not to use them I guess.

Thank you for the help.

Closed Thread