How to print selected data in VB 6 Data Report

5 pts.
Tags:
VB Data Report
Visual Basic
Visual Basic 6
we were about to create a system that generate eport such as daily weekly monthly and annual... and we dont know how to do it.. plz.. help us..

Answer Wiki

Thanks. We'll let you know when a new response is added.

Example
1. add textbox and command1 in a Form
2. add label1 and set a caption “Bill No”
4. add dataenvironment1
5. Set connection1 in Dataenvironment of your database file name
5. add command1 in Dataenvironment and type a query in sql as following example
SELECT * FROM BillTable WHERE Billno = ?;
6. Design a report of Datasource : DataEnvironment1 and Datamember Command1
7. Add Click Event of Command Button in Form
Private Sub Command1_Click()
If Dataenvironmanet1.Connection1.State<> 0 Then
Dataenvironmanet1.Connection1.Close
End If
Dataenvironmanet1.Connection1.Open
Dataenvironmanet1.Command1 Text1.Text
DataReport1.Show
End Sub
8. Run This Program
9. Type a bill No in Textbox
10. Click on Command1
You can See only selected BillNo Report

Discuss This Question: 17  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • carlosdl
    I think you will need to be more specific in your question in order to get useful responses. What exactly is what you don't know how to do it ?
    77,180 pointsBadges:
    report
  • AS400Operator
    How do I create a report from daily backup?
    80 pointsBadges:
    report
  • proseo
    lets make some example, I have one form then i have 4 textboxes, the name,address,age,gender then one button. after filling all the required fields. The inputted datas will normally add to the database, what I want is after clicking the button, I will generate a report just for the details of the my latest action.
    10 pointsBadges:
    report
  • nivron006
    Hi Jadejaashok,

    How can i print a record between two Bill No.?

    It is possible ?

    Instead you will input 1 bill no. you will input 2 bill number so you cant print the records between bill number you type.

    Hope for your response.

    Thank you,
    Norvin 
    95 pointsBadges:
    report
  • TheRealRaven
    To print between two BillNos, you need to SELECT ... WHERE BillNo BETWEEN BillNo1 AND BillNo2.

    It's hard to be sure how BillNo1 and BillNo2 will actually become part of the SELECT statement. Different varieties of SQL and different client technologies can do it slightly differently. Actual client info is needed.

    But basically, the SELECT statement needs to be coded to 'select' the desired rows from the table.
    18,995 pointsBadges:
    report
  • carlosdl
    Without more details, Raven's answer is probably the best suggestion anyone could recommend.

    If you need more help, I would recommend creating a new question, making sure to include all the pertinent details about your program, the platform, and the problem you have.
    77,180 pointsBadges:
    report
  • nivron006
    Hi TheRealRaven,

    My two bill no. will base on the value of text1.text and text2.text.

    In my command1 under data environtment have sql statement(See Below)

    SELECT * FROM Customers WHERE CompanyName = ? and CompanyName = ?;

    My commandbutton has this code:

    Private Sub Command1_Click()
    If DataEnvironment1.Connection1.State <> 0 Then
    DataEnvironment1.Connection1.Close
    End If
    DataEnvironment1.Connection1.Open
    DataEnvironment1.Command1 Text1.Text
    DataEnvironment1.Command1 Text2.Text
    DataReport1.Show
    End Sub


    From there, i could filter the bill no. base value of my 2 textboxes.

    But it results error, it said "Arguments not optional"

    Hope you get my point?

    Thank you,
    Norvin

    95 pointsBadges:
    report
  • nivron006
    My Point here is to filter 2 records or between depends from the value of my text1.text and text2.text.
    95 pointsBadges:
    report
  • nivron006
    Somebody can help me?
    95 pointsBadges:
    report
  • carlosdl
    I missed this...

    Did you solve your problem?

    Your SQL statement didn't include any condition related to those text boxes.
    77,180 pointsBadges:
    report
  • nivron006
    I still did not solved this problem.

    Hope you help me Sir carlosdl.

    Did you get my point sir regarding my concern.
    95 pointsBadges:
    report
  • carlosdl
    I think I understand.

    Your query must be something like this:

    SELECT * FROM Customers WHERE CompanyName = ? AND bill_no BETWEEN ? AND ?;


    And you need to pass your text items' text as parameters to the query,  in the way you are doing with the company name.
    77,180 pointsBadges:
    report
  • nivron006
    I will put this on my command:

    SELECT * FROM Customers WHERE CompanyName = ? AND bill_no BETWEEN ? AND ?;
    In my command button, what command should i put to open the datareport, like this?
    If DataEnvironment1.Connection1.State <> 0 Then
    DataEnvironment1.Connection1.Close
    End If
    DataEnvironment1.Connection1.Open
    DataEnvironment1.Command1 Text1.Text
    DataEnvironment1.Command1 Text2.Text
    DataReport1.Show
    Thanks sir carlosdl.
    95 pointsBadges:
    report
  • nivron006
    Do you have skype sir carlos?
    95 pointsBadges:
    report
  • carlosdl
    Sorry, I don't remember how things were done in VB6, and I don't have it installed to test.

    Maybe you need to pass the parameters to the command this way:

    DataEnvironment1.Command1 CompanyTextBox.Text Text1.Text Text2.Text

    77,180 pointsBadges:
    report
  • nivron006
    ahh ok, i will try this right now.
    95 pointsBadges:
    report
  • nivron006
    I dont need to filter the company name, only the bill no. but this time i will filter between records base of the value of text1.text and text2.text.

    I try this code:

    Private Sub Command1_Click()

    If DataEnvironment1.Connection1.State <> 0 Then
    DataEnvironment1.Connection1.Close
    End If
    DataEnvironment1.Connection1.Open
    DataEnvironment1.Command1 Text1.Text, Text2.Text
    DataReport1.Show
    End Sub

    but it shows error (Please see below):

    Data shape command text contains a syntax error at or near position 143 in the command. The text near the error is: "Command2 RELATE ) AS Command2.

    What does the error means?
    95 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: