Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: RE: How to create a report using code rather than the re port- designer tools.


Message #1 by "Bob Bedell" <bdbedell@m...> on Fri, 31 Aug 2001 20:22:14 -0400
Hi Daniel,



I was pretty clueless about how to use code to control report formatting 

until I ran across Microsoft?s Sample Reports database (available at the 

Download Center) through knowledge base article Q231851. Just go to 

www.microsoft.com and type Q231851 in the search box. It will take you right 

to the download.



One of the reports in the reports sample database (elaborated upon in 

Q210589) demonstrates how to eliminate white space in reports if the control 

happens to contain a null value. It?s done by playing with the CanGrow and 

CanShrink properties of the controls on your report.



Anyway, the sample database contains examples of 28 code driven report 

formats, each supported by it?s own KB article. Great resource. You might 

find what you?re looking for there.





>From: daniel.eugen@m...

>Reply-To: "Access" <access@p...>

>To: "Access" <access@p...>

>Subject: [access] RE: How to create a report using code rather than the re  

>    port designer tools.

>Date: Fri, 31 Aug 2001 15:40:38

>

>Apologies for not replying to your prompt feedback.

>

>You actually did understand what I was trying to achieve, and I sort of

>thought of the same layout as you recemmended.  However, if I just make

>certain elements in the report invisible, it would make the report layout

>very unsightly with many gaps in between lines.

>

>That's why I'm trying to either create that report based on the chose

>fields, or somehow limit the fields that are not just visible but actually

>even present on the report page.

>

>I've never worked with Filters, or reports extensively for that matter,

>but I'll give this a try.

>

>Thank you again.

>

>

> > I don't know exactly what your needs are, but one thing to maybe try is

>use

> > a single report with all of the fields on it, based just on the

>underlying

> > table.  Then when your user clicks "generate report", you build up a

>filter

> > string to pass to the report, and programatically set unchosen field

> > controls .Visible property to False.

> >

> > HTH,

> >

> > -Roy

> >

> > -----Original Message-----

> > From: daniel.eugen@m... [mailto:daniel.eugen@m...]

> > Sent: Thursday, August 16, 2001 12:21 PM

> > To: Access

> > Subject: [access] How to create a report using code rather than the

> > report designer tools.

> >

> >

> > Scenario:

> >

> > I have a form with 20 fields on it.  A user selects which of the fields

> > are to be used in a query and specifies values for those chosen fields

> > which are to be used to build up a string that will be used as the 

>query.

> >

> > When the user completes the fields and clicks the "generate report"

> > button, I would like to have a report created based only on the entries

> > chosen.

> >

> > Being able to control the layout of the report would be great, but right

> > now I have no idea how I can code the generating of a report based on a

> > query that only exists momentarily during the execution of the

>application.

> >

> > I've tried to figure out if I can use the Report Wizard, but it only

> > brings up a blank report.

> >

> > Any help would be most appreciated.

> >

> > Thanks.

Message #2 by "Bob Bedell" <bdbedell@m...> on Fri, 31 Aug 2001 20:57:04 -0400
Hi Daniel,



Just an after thought. The output of the detail section of any report you 

will ever create is controlled by ?behind-the-scenes? looping code. I didn?t 

realize that until I began writing code behind the detail section of 

reports, set a few break points, and watched the loops execute. 

Interestingly, Access handles these looping structures for you, 

automatically. Though it happens quickly, the lines of the detail section of 

any report are written one at a time, and each is the output of one more 

iteration of the same loop structure. That means that every discrete line of 

code that appears in the detail section of your reports can be controlled by 

code, i.e., each and every line could be formatted differently ? hidden, 

visible, different formatting, etc.



Detail section formatting is usually controlled by writing code for the 

Detail_Print event or the Detail_Format event. Try some of the reports in 

the sample database that use these events, but set a break point at the 

event header. You?ll see that Access automatically iterates the event for 

every record in your report?s recordset.







>From: daniel.eugen@m...

>Reply-To: "Access" <access@p...>

>To: "Access" <access@p...>

>Subject: [access] RE: How to create a report using code rather than the re  

>    port designer tools.

>Date: Fri, 31 Aug 2001 15:40:38

>

>Apologies for not replying to your prompt feedback.

>

>You actually did understand what I was trying to achieve, and I sort of

>thought of the same layout as you recemmended.  However, if I just make

>certain elements in the report invisible, it would make the report layout

>very unsightly with many gaps in between lines.

>

>That's why I'm trying to either create that report based on the chose

>fields, or somehow limit the fields that are not just visible but actually

>even present on the report page.

>

>I've never worked with Filters, or reports extensively for that matter,

>but I'll give this a try.

>

>Thank you again.

>

>

> > I don't know exactly what your needs are, but one thing to maybe try is

>use

> > a single report with all of the fields on it, based just on the

>underlying

> > table.  Then when your user clicks "generate report", you build up a

>filter

> > string to pass to the report, and programatically set unchosen field

> > controls .Visible property to False.

> >

> > HTH,

> >

> > -Roy

> >

> > -----Original Message-----

> > From: daniel.eugen@m... [mailto:daniel.eugen@m...]

> > Sent: Thursday, August 16, 2001 12:21 PM

> > To: Access

> > Subject: [access] How to create a report using code rather than the

> > report designer tools.

> >

> >

> > Scenario:

> >

> > I have a form with 20 fields on it.  A user selects which of the fields

> > are to be used in a query and specifies values for those chosen fields

> > which are to be used to build up a string that will be used as the 

>query.

> >

> > When the user completes the fields and clicks the "generate report"

> > button, I would like to have a report created based only on the entries

> > chosen.

> >

> > Being able to control the layout of the report would be great, but right

> > now I have no idea how I can code the generating of a report based on a

> > query that only exists momentarily during the execution of the

>application.

> >

> > I've tried to figure out if I can use the Report Wizard, but it only

> > brings up a blank report.

> >

> > Any help would be most appreciated.

> >

> > Thanks.


  Return to Index