CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    13

    VB6 Data Report Problem--Need Help Fast

    I posted the question about Crystal Reports below. Sorry for posting twice, but I just read elsewhere in this list that it is possible to use an existing ADO recordset as the data source for a VB6 DataReport, and then bind the report controls to the recordset fields. I tried

    Set DataReport1.DataSource = [my recordset name]

    but I keep getting the "Invalid Data Source"
    message. Can anyone give me the code to do this with the Data Report?

    Thanks,

    John


  2. #2
    Join Date
    May 1999
    Posts
    12

    Re: VB6 Data Report Problem--Need Help Fast

    Hi John.
    I had the same trouble. Try to do the following steps and i think it´ll work

    1. Catch the error
    On Error Resume NExt
    2.And then bind the fields of your datareport with
    the fields of your Recordset.
    3. At last, refresh your report
    Me.Refresh

    Put the previous code in the event initialize of the DataReport.

    It works for me. I´m working with ADODB Recordsets
    filled calling a ADODB.Command.

    If you don´t success, report me the trouble and i´ll try to help you, but be sure it works.

    Hope it helps!
    Bye
    JaIme



  3. #3
    Join Date
    Apr 1999
    Posts
    14

    Re: VB6 Data Report Problem--Need Help Fast

    Here is the sample code for running reports with ADO recordsets. If you have any more question feel free to mail me. I have more stuff on how to develop grouping reports using ADO's and recordsets. My email Id is [email protected]

    Good luck

    The following code goes into the module:

    option Explicit
    public MyConn as ADODB.Connection
    public myRec as ADODB.Recordset
    public myRec1 as ADODB.Recordset

    Sub main()
    set myRec = new ADODB.Recordset
    set myRec1 = new ADODB.Recordset
    set MyConn = new ADODB.Connection

    With MyConn
    .Provider = "Microsoft.jet.oledb.3.51"
    .Open "C:\Program Files\Microsoft Visual Studio\VB98\Biblio.mdb"
    End With


    myRec1.Open "SELECT * From Publishers ", MyConn, adOpenStatic, adLockOptimistic

    Form1.Show

    End Sub




    The following code goes into the command1 click event


    DataReport1.Visible = true




    The following code goes into the report initialisation section:


    private Sub DataReport_Initialize()

    With DataReport1
    set .DataSource = myRec1
    .Sections.Item(3).Controls.Item(1).DataField = myRec1.Fields(0).Name
    .Sections.Item(3).Controls.Item(2).DataField = myRec1.Fields(1).Name
    End With
    End Sub







Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured