Binding DataReport (in VB6) to custom recordset

    Question by:


    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?

    Good Question?

    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

    Ask Your Tech Question. Get Expert Solutions.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.

    Top Expert Contributor

    Essential articles and videos from the Experts

    More valuable questions with Expert answers


    RELATED TOPICS view all topics

    1. MS Excel
    2. VB Script
    3. MS Access
    4. .NET Programming
    5. Visual Basic.NET
    6. MS Development
    7. Programming Languages
    8. Programming
    9. MS Office
    10. MS Word