PoisonedHeart 4 Junior Poster in Training

Hi to all and good day...

I'm still studying about vb 6's data report designer and the data environment...but what i need to know is
how can i make or generate a report at run time...

for example, generate report for the employee names.
(names of the employees will populate the report and nothing else...
or generate report for orders...

something like that...

the user will choose between the two options (maybe an option button will be OK to use.) then after the user chooses one and click the button 'generate report'...) the report will be generated according the choices..

I have search through the net for some samples about the data report designer, but what i see is, the report was build during the design time.

Thanks in advance...:)

This forum helps me a lot, thanks to all of you

Dani AI

Generated

— two simple, reliable ways to generate different reports at run time in VB6 without trying to redesign the report layout dynamically.

One: design a small report for each output (EmployeeReport, OrdersReport). At runtime prepare the data (set the SQL or parameters on the DataEnvironment command or fill an ADO recordset) and then show the report that matches the option button. This is the simplest and least error-prone approach:

Private Sub cmdGenerate_Click()
    If optEmployees.Value Then
        DataEnvironment1.Commands("Employees").CommandText = _
            "SELECT EmployeeID, LastName, FirstName FROM Employees"
        DataReportEmployees.Show
    Else
        DataEnvironment1.Commands("Orders").CommandText = _
            "SELECT OrderID, OrderDate, CustomerName FROM Orders"
        DataReportOrders.Show
    End If
End Sub

Two: use one report template and switch the data it binds to. Prepare an ADODB.Recordset at runtime (or set a DataEnvironment command text/parameters) and bind that recordset to the report source before calling Show. This keeps layout in one place but requires the report fields to be compatible with both datasets.

Practical tips and gotchas:

  • Ensure the project references include the ADO library and the Data Report Designer. Test your SQL in a query tool or immediate window first.
  • If your DataEnvironment command uses parameters, set them in code before showing the report.
  • Handle empty recordsets (show a message or skip the report) to avoid blank output.
  • If you need very dynamic layout (different columns, grouping, or formatting), consider a third-party engine (Crystal/ActiveReports) — VB6 DataReport is fine for simple list/detail reports but is limited for heavy runtime layout changes.

These two patterns cover most run-time report needs and match the option-button approach you described.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.