Link to home
Start Free TrialLog in
Avatar of edwinson
edwinsonFlag for United States of America

asked on

Dynamic Data Report

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.
Avatar of Brendt Hess
Brendt Hess
Flag of United States of America image

>> 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)
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q240019
HOWTO: Dynamically Populate a Group Data Report in Visual Basic (Q289793)
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q289793

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

Anthony
Avatar of edwinson

ASKER

Anthony,

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.
ASKER CERTIFIED SOLUTION
Avatar of Valliappan AN
Valliappan AN
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Fair point.  There are workarounds, but I suspect you are right in looking elsewhere.

Anthony
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
'grid.
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
  rst.MoveNext
Loop

 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.


   
Provided some good direction on where to solve the problem.
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.
Cheers.
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.