Dynamic Data Report

Posted on 2002-04-01
Last Modified: 2007-12-19
The application I am building requires some relatively simple reporting capabilities.  Primarily I need to incorporate the ability to print the contents of a Mshflexgrid when the user requests.

The application is a data mining application where a user could import virtually any file for analysis purposes. As such it is impossible to build a static Data Report.

My first thought was to utilize the Data Report in VB6, but found that it doesn't seem to allow dynamic creation of reports.

I worked with the printer object, but found it sucked particularly if the data went past the margins.  In other words it was too complex to program properly.

The only thing I think of to work here is to dump the contents of the ADO recordset/datasource into a RichTextbox then printing from that.

As a followup, is there a dialog box OCX or something that can be used to set the options of the printer object? IE margins, zoom, etc?  Seems really stupid to have an object like that and nobody built an OCX to set properties.  I already am using the common dialog control to present the typical vanilla print options, but I need to be able to scale the printout to fit a page, set margins, etc. just like every other program on the planet.
Question by:edwinson
  • 4
  • 2
  • 2
  • +1
LVL 32

Expert Comment

ID: 6911003
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6911360
>> My first thought was to utilize the Data Report in VB6, but found that it doesn't seem to allow dynamic
creation of reports. <<

Actually you can and you do not even need the DataEnvironment (other than for design purposes)

Take a look at the following articles from MSDN:
HOWTO: Dynamically Populate a Data Report in Visual Basic (Q240019);en-us;Q240019
HOWTO: Dynamically Populate a Group Data Report in Visual Basic (Q289793);EN-US;q289793

On the other hand, it would only be fair to add that the DataReport is not supported in .NET


Author Comment

ID: 6911456

These two references seem OK, but there is a problem.  The text suggests you need to know how many fields there will be in the report during design time.  The code segments then simply process through each of the controls on the report and bind data fields to them at runtime.

This works fine if you already know what the data report will contain.  In my situation, a user could import any file so I don't know how many fields are going to be in the ultimate report during design time.  Therefore I cannot anticipate the number of controls that will be needed.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Accepted Solution

Valliappan AN earned 100 total points
ID: 6912628
You can try this:
(Printer control)

(RTF Print Preview)

Hope it helps.
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6913045
Fair point.  There are workarounds, but I suspect you are right in looking elsewhere.


Author Comment

ID: 6913679
I came up with a cheesy solution but still looking.

I built a form with a richtextbox control in it.
I also built a function to create a string to contain the contents from the grid/recordset.

Code in the "preview form"
Grid1 - a reference to the grid containing the data I want to print.  

Private Sub Form_Load()
Dim rst As New ADODB.Recordset, mfield As ADODB.Field
Dim strText As String
Set rst.DataSource = Grid1.DataSource

'just in case this form opens and there is no data in the
If rst.State = 0 Then Exit Sub

'build the string headers
For Each mfield In rst.Fields
  strText = strText & vbTab & mfield.Name
Next mfield
strText = strText & vbCrLf

'now build the field values
Do Until rst.EOF
  For Each mfield In rst.Fields
     strText = strText & vbTab & mfield.Value
  Next mfield
  strText = strText & vbCrLf

 RichTextBox1.Text = strText
 Set rst = Nothing
End Sub

I then use a PrintRTF function when the print is requested:
I gotta tell you this is not exactly what I wanted to accomplish.  It leaves a heck of a lot to be desired.

a.) Printer dialog still hasn't been addressed (ie Page Margins, etc.)
b.) Building all of the stinking options to modify the text etc.!!
c.) all the other typical reporting type things.


Author Comment

ID: 7070590
Provided some good direction on where to solve the problem.

Expert Comment

by:Valliappan AN
ID: 7071821
Thanks edwinson. Did you use the RTF Preview or what?

But then, why Grade B, though it matters not much.

Glad I could help you.

Author Comment

ID: 7072592
I used a combination of things to get a rudimentary function.  

I ended up working with an HTML document object to build a table in HTML.  This way I could be a bit more flexible.

I guess the B was for providing direction on the ultimate solution.

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question