Binding DataReport (in VB6) to custom recordset

Visual Basic Classic Question

I nave designed a report using DataReport designer in VB6 (NOT Crystal). This report is bound to some DataEnvironment in design time. I want to bind my report in runtime to my custom ADODB.Recordset (having just the same structure) How to do it?

Default Text

Verified Answer?

The member who asked this question verified this comment provided the solution that solved their problem.

by:Posted on 1999-03-24 at 21:45:12ID: 1500665

4 ways to skin this cat that I can think of:

Way #1:

'The path of least resistance'

Step 1:

Create your commands in the data environment.

Step 2:

Create a DataReport based on these commands.

Step 3:

Find out what the entire SQL statement looks like for your commands (In ADO child command's SQL is embedded into the parent's SQL using the SHAPE command)

Dim myCmd as Command

For each myCmd in DataEnvironment1.Commands
   If myCmd.Name = "[Insert the name of your parent command here]" Then
      Debug.Print myCmd.CommandText
      Exit For
   End IF
Next myCmd

Step 4:

Determine what it is you want to change about this command or sub-commands and locate those spots in the command text.

Step 5:

Write a report-printing routine

Now you can write a routine that replaces the command text in the parent command with the changes you wanted to make.

That routine might look something like this....


Public Sub PrintThatReport(Optional Byval CompanyID as String)

   Dim myRpt as DataReport
   Dim myCmd as Command

   If CompanyID <> "" Then
      Set myRpt = New CompanyReport

      For Each myCmd In DataEnvironment1
         If myCmd.Name = "cmdCompany" Then
            myCmd.CommandText = "SELECT tblCompany.* FROM tblCompany WHERE tblCompany.fldCompanyID = '" & CompanyID & "'"
            Exit For
         End If
      Next myCmd
   End If

End Sub

This content is available to Experts Exchange members

See the answer now
with your Free 30 Day Trial

Get unlimited access to solutions & experts

  • 4,169,477 solved questions
  • 3,805 articles & videos
  • 15,413 tech experts

Get Access Now

Need a customized answer?
Ask your question for one-on-one assistance. We will email you when an expert has commented on your question.

We will never share this with anyone. Privacy Policy Terms of Use

Select topics

You may select up to five topics.


Related Articles

Related Questions