473,382 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to format the detail of a dynamically created subreport

I have a form that contains a command button. The command button's
OnClick event builds a report using the CreateReport and
CreateReportControl functions and then opens the main report. I set
the OnFormat property of the detail section in the subreport to a
function which is located in a standard module. I am not able to
access the subreport nor it's controls in the module. I need to hide a
text box in the subreport if there is no information in any of the rows
in the detail of the subreport. Any help is appreciated. I have
posted the code below.

Form Code:

Private Sub cmdPreviewReport_Click()

' Create the subreport
' --------------------

Set rs = CurrentDb.OpenRecordset("tblSGPrices")

Set rpt = CreateReport(CurrentDb.Name)
DoCmd.RunCommand acCmdReportHdrFtr
intColumnCount = rs.Fields.Count

' Create Header section labels and Detail section text boxes
' ----------------------------------------------------------

For i = 0 To intColumnCount - 1

' Create the detail section text boxes and set controlsource
' ----------------------------------------------------------
Set tbox = CreateReportControl(rpt.Name, acTextBox, acDetail)
tbox.Name = "col" + Format(i)
rpt.Controls("col" + Format(i)).ControlSource =
rs.Fields(i).Name

' Create the Header section labels
' --------------------------------

Set lbl = CreateReportControl(rpt.Name, acLabel, acHeader)
lbl.Name = "header" + Format(i)
Next
rpt.Section(acDetail).OnFormat = "=FormatDetailSG()"
End Sub
Standard Module:

Function FormatDetailSG()
Dim i As Integer
Dim rpt As Report
Set rpt = Reports("Report1") 'THIS IS WHERE I GET THE FOLLOWING
ERROR:

(ERROR 2451 - The report name 'Report1' you entered is misspelled or
refers to a report that isn't open or doesn't exist)

For i = 0 To rpt.Section(acDetail).Controls.Count - 1
If Reports(SGToFormat)("col" + Format(i)) <> "" Then
Reports(SGToFormat)("col" + Format(i)).Visible = False
Else
Reports(SGToFormat)("col" + Format(i)).Visible = True
End If
Next i
End Function

Nov 13 '05 #1
3 7423
Quite aside from the fact that I'm perplexed as to quite why you'd be
wanting to do all this programmatically anyhow, I don't see any code
creating or opening a report named Report1, so it doesn't seem too odd that
Access can't find it.
Is there more you're not telling us?

<km****@stcroixknits.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I have a form that contains a command button. The command button's
OnClick event builds a report using the CreateReport and
CreateReportControl functions and then opens the main report. I set
the OnFormat property of the detail section in the subreport to a
function which is located in a standard module. I am not able to
access the subreport nor it's controls in the module. I need to hide a
text box in the subreport if there is no information in any of the rows
in the detail of the subreport. Any help is appreciated. I have
posted the code below.

Form Code:

Private Sub cmdPreviewReport_Click()

' Create the subreport
' --------------------

Set rs = CurrentDb.OpenRecordset("tblSGPrices")

Set rpt = CreateReport(CurrentDb.Name)
DoCmd.RunCommand acCmdReportHdrFtr
intColumnCount = rs.Fields.Count

' Create Header section labels and Detail section text boxes
' ----------------------------------------------------------

For i = 0 To intColumnCount - 1

' Create the detail section text boxes and set controlsource
' ----------------------------------------------------------
Set tbox = CreateReportControl(rpt.Name, acTextBox, acDetail)
tbox.Name = "col" + Format(i)
rpt.Controls("col" + Format(i)).ControlSource =
rs.Fields(i).Name

' Create the Header section labels
' --------------------------------

Set lbl = CreateReportControl(rpt.Name, acLabel, acHeader)
lbl.Name = "header" + Format(i)
Next
rpt.Section(acDetail).OnFormat = "=FormatDetailSG()"
End Sub
Standard Module:

Function FormatDetailSG()
Dim i As Integer
Dim rpt As Report
Set rpt = Reports("Report1") 'THIS IS WHERE I GET THE FOLLOWING
ERROR:

(ERROR 2451 - The report name 'Report1' you entered is misspelled or
refers to a report that isn't open or doesn't exist)

For i = 0 To rpt.Section(acDetail).Controls.Count - 1
If Reports(SGToFormat)("col" + Format(i)) <> "" Then
Reports(SGToFormat)("col" + Format(i)).Visible = False
Else
Reports(SGToFormat)("col" + Format(i)).Visible = True
End If
Next i
End Function

Nov 13 '05 #2
Ken
The reason I am doing this in code is because I am using a crosstab
query to create the data for the subreport and therefore the number of
columns are dynamic. So I have to create the text boxes in code to get
the number necessary to hold the data. When I create the subreport
using the CreateReport function, the default name of the report is
Report1. The data I am creating in the crosstab query is in this form:

Style Color Small Medium Large X-Large XX-Large 3XL
1234 Red A A A B A
1234 Black A A
4567 Black A A A
8910 White A A A

The letters (A,B) under the Size columns represent a price code and
that the Style/Color is available in that Size. Each Style/Color may
not be available in all Sizes, so I want to hide the column (Size) if
there is nothing to display. So, I need to do this in the
Detail_Format event of the subreport. Because I am creating this
subreport in code, I am assigning a function to the OnFormat property.
The only place I know that the program can see the function is in a
module, however when I try to access the subreport or it's controls in
the function it comes up with the error listed above. I am assuming
that the subreport is out of scope in the module but I don't know how
else I would accomplish this.

Nov 13 '05 #3
Ken
I have found the answer to my problem. I used the following to access
the controls on the subreport:

Reports("mainreport").Section(acDetail).Controls(" report1").Controls("col1")

This gives me access to a text box named "col1".

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tony | last post by:
Hi, I have dynamically created a PDF document in memory as a FileOutputStream Now I have to get it into a DB2 table, storing it as a BLOB. The table has a document id, document name, some date...
6
by: Thomas | last post by:
Hi, I'm having a problem with the dynamically created inputfields in Internet Explorer. The situation is the following: - I have a dynamically created table with a textbox in each Cell. - It...
2
by: R Duke | last post by:
I have tried everything I can think of to change the visible property of a design time created control from a dynamically created control's command event handler. Here is the scenario. I have...
6
by: conckrish | last post by:
Hi all Can anyone tell me how to add a click event for a user control page dynamically??? Thanx Krish.
7
by: rsaffy | last post by:
I am having trouble with my dynamically created button's event handling. I read that the buttons need to be recreated on every trip to the server, but how exactly do you do that when the datagrid...
4
by: assgar | last post by:
Hi I am stuck on a problem. I use 3 scripts(form, function and process). Development on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. The form displays...
5
by: Amoril | last post by:
I've read quite a few different message on various boards and for some reason I'm still having trouble wrapping my head around this viewstate maintenance and trying to get these dynamically created...
2
by: Nathan Sokalski | last post by:
I have LinkButtons that are dynamically created in one of the PostBack events. They must be created in the PostBack event because one of the variables required to determine which ones to create...
5
by: davidson1 | last post by:
Hai Friends, I have the following code for Dynamically Created Tables, I have created the panel in the webform....... Dim tab5 As New Table Dim row1 As New TableRow Dim cell1 As...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.