Solved

Dynamic Data Report

Posted on 2002-04-01
9
298 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
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 32

Expert Comment

by:bhess1
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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now