Solved

Dynamic Data Report

Posted on 2002-04-01
9
314 Views
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.
0
Comment
Question by:edwinson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 32

Expert Comment

by:Brendt Hess
ID: 6911003
0
 
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)
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
0
 
LVL 1

Author Comment

by:edwinson
ID: 6911456
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.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 9

Accepted Solution

by:
Valliappan AN earned 100 total points
ID: 6912628
You can try this:

http://www.vbcity.com/pubs/article.asp?alias=qprinter
(Printer control)

OR

http://www.a1vbcode.com/app.asp?ID=337
(RTF Print Preview)

Hope it helps.
0
 
LVL 75

Expert Comment

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

Anthony
0
 
LVL 1

Author Comment

by:edwinson
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
'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.


   
0
 
LVL 1

Author Comment

by:edwinson
ID: 7070590
Provided some good direction on where to solve the problem.
0
 
LVL 9

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.
Cheers.
0
 
LVL 1

Author Comment

by:edwinson
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.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month10 days, 15 hours left to enroll

628 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