Results 1 to 12 of 12

Thread: Data Reports Breaking

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    307

    Data Reports Breaking

    Very new to VB6 and here is what i am trying to achieve.

    I am making a report with the data reports tool.

    Here is some code
    VB Code:
    1. Private Sub cmdshow_Click()
    2. 'Create a RS
    3. Dim RS2 As ADODB.Recordset
    4. Set RS2 = New ADODB.Recordset
    5.  
    6. 'Create a basic Sql string
    7. Dim strSQL As String
    8. strSQL = "SELECT * FROM msds where lastmodified > '2007-01-18' order by companyname"
    9.  
    10. 'Open the Recordset
    11. RS2.Open strSQL, "driver={MySQL ODBC 3.51 Driver};database=msds;Option=3;server=" & PathMySQL & ";uid=;pwd=;"
    12.  
    13. 'Bind to the report
    14. Set DataReport2.DataSource = RS2
    15.  
    16. 'Preview the report
    17. DataReport2.Show vbModal
    18.  
    19. 'Cleanup
    20. RS2.Close
    21. Set RS2 = Nothing
    I want to break when the company name changes.
    For example sample data

    COMPANYA CHEMICALA
    COMPANYA CHEMICALB
    COMPANYB CHEMICALA

    I would want
    COMPANYA CHEMICALA
    COMPANYA CHEMICALB

    And when i am done listing chemicals for that company start a new page
    COMPANYB CHEMICALA

    Hopefully i am clear enough. Thanks!!
    Last edited by Hack; Jan 30th, 2007 at 12:19 PM. Reason: Added [vbcode] [/vbcode] tags

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Data Reports Breaking

    Moved to reporting

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Data Reports Breaking

    The only way to create a page break is to have a Group Header/Footer (set the ForcePageBreak property).

    The only way to Group the report is to use a Hierarchical recordset created with the Shape command.

    VB Code:
    1. strSQL = "Shape {SELECT CompanyName FROM msds where lastmodified > '2007-01-18'} " & _
    2. "Append ({Select CompanyName, ChemicalField From msds} As Details " & _
    3. "Relate CompanyName To CompanyName)"

    You also need to change your connection string to use the MSDataShape provider.

    VB Code:
    1. RS2.Open strSQL, "provider=MSDataShape;data provider={MySQL ODBC 3.51 Driver};database=msds;Option=3;server=" & PathMySQL & ";uid=;pwd=;"

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    307

    Re: Data Reports Breaking

    Ok that makes sense and I am a little closer.
    I have an error on this line
    VB Code:
    1. RS2.Open strSQL, "provider=MSDataShape;data provider={MySQL ODBC 3.51 Driver};database=msds;Option=3;server=" & PathMySQL & ";uid=;pwd=;"

    It tells me class is not registered. Perhaps there are some more objects i need to add to my references?
    Quote Originally Posted by brucevde
    The only way to create a page break is to have a Group Header/Footer (set the ForcePageBreak property).

    The only way to Group the report is to use a Hierarchical recordset created with the Shape command.

    VB Code:
    1. strSQL = "Shape {SELECT CompanyName FROM msds where lastmodified > '2007-01-18'} " & _
    2. "Append ({Select CompanyName, ChemicalField From msds} As Details " & _
    3. "Relate CompanyName To CompanyName)"

    You also need to change your connection string to use the MSDataShape provider.

    VB Code:
    1. RS2.Open strSQL, "provider=MSDataShape;data provider={MySQL ODBC 3.51 Driver};database=msds;Option=3;server=" & PathMySQL & ";uid=;pwd=;"

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    307

    Re: Data Reports Breaking

    OK i got it running better now.
    By changing
    data provider={MySQL ODBC 3.51 Driver};
    over to driver={MySQL ODBC 3.51 Driver};

    I am now breaking on companyname.
    However if i try to put the field prodname in the detail line i get an error

    Datafield(prodname) not found. I will slowly get this worked out!

    By way msdsnum is the key in the file, do i need to incorporate that into the sql?
    Last edited by melvin74; Jan 30th, 2007 at 02:49 PM.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    307

    Re: Data Reports Breaking

    Ok here is the most latest

    VB Code:
    1. Dim RS2 As adodb.Recordset
    2. Set RS2 = New adodb.Recordset
    3. Dim product As String
    4.  
    5. 'Create a basic Sql string
    6. Dim strSQL As String
    7. 'strSQL = "SELECT * FROM msds where lastmodified > '2007-01-18' order by companyname"
    8. strSQL = "Shape {SELECT  msdsnum, CompanyName, prodname FROM msds where lastmodified > '2007-01-23' order by companyname} " & _
    9. "Append ({Select msdsnum, CompanyName, prodname From msds} As Details " & _
    10. "Relate msdsnum To msdsnum)"
    11.  
    12. 'Open the Recordset
    13. RS2.Open strSQL, "provider=MSDataShape;driver={MySQL ODBC 3.51 Driver};database=msds;Option=3;server=" & PathMySQL & ";uid=;pwd=;"
    14.  
    15. 'Bind to the report
    16. Set DataReport2.DataSource = RS2
    17.  
    18. 'Preview the report
    19. DataReport2.Show vbModal
    20.  
    21.  
    22. 'Cleanup
    23. RS2.Close
    24. Set RS2 = Nothing

    I am very close, but its now printing on 3 pages. Not putting the top two together.

    CompanyA
    CompanyA chemical1


    CompanyA
    CompanyA Chemical2

    CompanyB
    CompanyB Chemical3

  7. #7
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Data Reports Breaking

    How many records does this query return?

    SELECT msdsnum, CompanyName, prodname FROM msds where lastmodified > '2007-01-23'

    That will be the number of Groups in your report and if you are page breaking after a group the number of pages as well.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    307

    Re: Data Reports Breaking

    This returns 3 records.
    However I truly only want two groups.

    I want page one to be
    CompanyA

    CompanyA chemical1
    CompanyA Chemical2

    and i want page 2 to be

    CompanyB

    CompanyB Chemical3

    I want one page to contain all chemicals for that company.
    Quote Originally Posted by brucevde
    How many records does this query return?

    SELECT msdsnum, CompanyName, prodname FROM msds where lastmodified > '2007-01-23'

    That will be the number of Groups in your report and if you are page breaking after a group the number of pages as well.

  9. #9
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Data Reports Breaking

    Don't use the msdsnum field. Since you have to create a Master/Detail from one table you will need to create the Master group based on the Company.


    VB Code:
    1. strSQL = "Shape {SELECT  Distinct CompanyName FROM msds where lastmodified > '2007-01-23} " & _
    2. "Append ({Select CompanyName, prodname From msds} As Details " & _
    3. "Relate CompanyName To CompanyName)"

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    307

    Re: Data Reports Breaking

    Quote Originally Posted by brucevde
    Don't use the msdsnum field. Since you have to create a Master/Detail from one table you will need to create the Master group based on the Company.


    VB Code:
    1. strSQL = "Shape {SELECT  Distinct CompanyName FROM msds where lastmodified > '2007-01-23} " & _
    2. "Append ({Select CompanyName, prodname From msds} As Details " & _
    3. "Relate CompanyName To CompanyName)"
    The issue i have now is when i have a textbox in the detail section for prodname i get "datafield(prodname) not found"


  11. #11
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Data Reports Breaking

    When you have a Hierarchical recordset you basically have recordsets within recordsets. You need to specify which recordset contains the field you want to display. To do that you use the DataMember property of the Control. In your case you named the Child recordset Details, so set the DataMember property to Details.

    The DataMember property of controls that display fields from the Master recordset can be left blank.

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    307

    Re: Data Reports Breaking

    That definitely gave me the desired results that i wanted!
    Only weird behavior i see happening is it there are some records being reported that dont fall in the query date range but they are still making it through.

    Thanks alot for all your help! Very helpful forum!
    Quote Originally Posted by brucevde
    When you have a Hierarchical recordset you basically have recordsets within recordsets. You need to specify which recordset contains the field you want to display. To do that you use the DataMember property of the Control. In your case you named the Child recordset Details, so set the DataMember property to Details.

    The DataMember property of controls that display fields from the Master recordset can be left blank.

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