How do I generate report in VB6?

Asked By 220 points N/A Posted on -
qa-featured

I am creating an Inventory System that will be submitted at the end of the semester. This system will summarized all the transactions that have been made by the user on how many is left, how many has been used etc. for a certain item. To generate a report I used Data Report and Data Environment to connect my database with it. But I am having a problem whenever I did some updates to my records the data in Data Report is not being updated. I need to restart the program again in order to update the records. Can anyone assist me with this one?

SHARE
Best Answer by Marcus Blake
Best Answer
Best Answer
Answered By 0 points N/A #126092

How do I generate report in VB6?

qa-featured

What you are going to do is to set the Data Report source directly to the database. If you are using an ADO, your code must be similar to this:

Under General Declaration of the Form or you can put this in Module so you can access the database without setting up another connection.

Codes in Module

====================================

    Public conn As New ADODB.Connection
    Public rec as New ADODB.Recordset

====================================

Create a Function for the connection of database

====================================

    Public Function dbconnection() As String
    Dbconnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "YourDataBase.mdb;Persist Security Info=False"
    End Function

====================================

    Setting up the source of DataReport
    Put this code under the print button

====================================

If rec.State = 1 Then   ‘Check first if the database is open

            rec.close

End if

rec.Open dbconnection ‘Opens the connection string

            Set rec = conn.Execute(("Select * From [YourTableName]")

            Set DataReport1.DataSource = rec ‘defining the source of DataReport

            DataReport1.Show

=====================================================================

If your are using ADODC or DAO its just similar on the above codes. You can also specify what tables to be shown in Data Report.

Answered By 0 points N/A #126094

How do I generate report in VB6?

qa-featured

Hi,

  • It's simple work. No matter which reporting tools you are using. Whenever you make update you need to save those changes. If you want to keep the updated and view updated report you need to restart the program of refresh the program.
  • To refresh the program you need to add a simple code like this:
  • If rec.State = 1 Then   ‘if the database is open
  •             rec.close
  • End if
  • rec.Open dbconnection ‘Opens the connection string
  •             Set rec = conn.Execute(("Select * From [UsingTableName]")
  •             Set DataReport1.DataSource = rec ‘the source of DataReport
  •             DataReport1.Show

Wish it will help you to resolve your problem. Do you have any farther quarry regarding this.

Thanks

Login/Register to Answer

Related Questions