Results 1 to 21 of 21

Thread: Report in Grid or Grid type control

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253

    Report in Grid or Grid type control

    Hi,

    I have a form which searches database on user critera and displays the result in FlexiGrid and if user wants to export the result to excel they can. Everything is working fine. But now I want to modify this program a little.

    The result in Grid is display like this:

    Year-----Field1-----Field2-----Field3
    2000----- A ------- A -------- A
    2001----- B ------- B -------- C
    2002----- C ------- C -------- C

    But I want this to be displayed in Grid like this:

    Year----2000-----2001----2002
    Filed1----A--------B-------C
    Field2----A--------B-------C
    Filed3----A--------B-------C


    How can I do this? Any help?

    Thanks

  2. #2
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Report in Grid or Grid type control

    can you post your program and/or its sourcecode? then someone can see how its written and offer advice.
    Quote Originally Posted by sillylady
    Hi,

    I have a form which searches database on user critera and displays the result in FlexiGrid and if user wants to export the result to excel they can. Everything is working fine. But now I want to modify this program a little.

    The result in Grid is display like this:

    Year-----Field1-----Field2-----Field3
    2000----- A ------- A -------- A
    2001----- B ------- B -------- C
    2002----- C ------- C -------- C

    But I want this to be displayed in Grid like this:

    Year----2000-----2001----2002
    Filed1----A--------B-------C
    Field2----A--------B-------C
    Filed3----A--------B-------C


    How can I do this? Any help?

    Thanks

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253

    Re: Report in Grid or Grid type control

    Here is code.


    VB Code:
    1. lngRow = adoRS.RecordCount
    2. lngCol = adoRS.Fields.Count
    3.  
    4. With ManuRatioGrid
    5.  
    6. .Cols = 2
    7. .Rows = 2
    8.  
    9. Do While Not adoRS.EOF
    10.  
    11. For j = 0 To lngRow
    12. For i = 0 To lngCol
    13.  
    14. .TextMatrix(i, j) = adoRS.Fields(i).Value
    15.  
    16. Next i
    17.  
    18. adoPrimaryRS.MoveNext
    19. Next j
    20.  
    21. Loop
    22. End With


    I think its working but the problem is if any cell of the Grid is empty, the for loop comes out.

  4. #4
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Report in Grid or Grid type control

    how many records supposed to be retrieved and how many have been displayed in the grid...i cudnt see any problem with this code, but how do u open the recordset ....
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253

    Re: Report in Grid or Grid type control

    Quote Originally Posted by ganeshmoorthy
    how many records supposed to be retrieved and how many have been displayed in the grid...i cudnt see any problem with this code, but how do u open the recordset ....
    It can retrieve any number of records and it displays the fetched records in the grid. I think the problem is when the inner for look encounter 'blank' cell in the Grid the loop exits.

  6. #6
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Report in Grid or Grid type control

    i hope you are filling only the blank cells with the resultset...
    may be instead of using
    VB Code:
    1. .TextMatrix(i, j) = adoRS.Fields(i).Value
    2. try this
    3. .TextMatrix(i, j) = Trim(adoRS.Fields(i).Value & "")
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253

    Re: Report in Grid or Grid type control

    Quote Originally Posted by ganeshmoorthy
    i hope you are filling only the blank cells with the resultset...
    may be instead of using
    VB Code:
    1. .TextMatrix(i, j) = adoRS.Fields(i).Value
    2. try this
    3. .TextMatrix(i, j) = Trim(adoRS.Fields(i).Value & "")
    I think i am not clear in my question. I am retrieving records in the ADO Recordset and trying to transfer those records in a GRID in this manner:
    Year-----2000
    Field1-----1
    Field2-----1
    Field3-----1

    instead of the usual display like:
    Year----Field1----Field2----Field3
    2000-----1--------1--------1


    the code which i have given here works fine the only problem is if any field in the row contains null value the for loop exits.

  8. #8
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Report in Grid or Grid type control

    this will take care of the null values of the recordset, have you trid it...
    VB Code:
    1. .TextMatrix(i, j) = Trim(adoRS.Fields(i).Value & "")
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253

    Re: Report in Grid or Grid type control

    Quote Originally Posted by ganeshmoorthy
    this will take care of the null values of the recordset, have you trid it...
    VB Code:
    1. .TextMatrix(i, j) = Trim(adoRS.Fields(i).Value & "")
    I tried it but the problem is same..........for statement comes out after i=3

    Do you have anyother idea?

  10. #10
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Report in Grid or Grid type control

    is it displaying any error or how do u say if it is null it comes out of for loop...have you checked the recordcount, how much it returns...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253

    Re: Report in Grid or Grid type control

    Quote Originally Posted by ganeshmoorthy
    is it displaying any error or how do u say if it is null it comes out of for loop...have you checked the recordcount, how much it returns...
    I have tested it by just setting the Grid Datasource to Ado recordset and it displays 6 records and 31 fields of which some have blank value.

  12. #12
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Report in Grid or Grid type control

    i asked the value of lngRow after you assign lngRow = adoRS.RecordCount
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253

    Re: Report in Grid or Grid type control

    Quote Originally Posted by ganeshmoorthy
    i asked the value of lngRow after you assign lngRow = adoRS.RecordCount
    lngRow=6 and lngCol=31

  14. #14
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Report in Grid or Grid type control

    i guess i is for your column and j is for your row values
    VB Code:
    1. .TextMatrix(i, j) = Trim(adoRS.Fields(i).Value & "")
    TextMatrix takes row, column, but you have given col, row check it and then in the MoveNext statement you have given some different recordset name and you have checked in the Do while some different recordset name... Do While adoRs.EOF and adoPrimaryRS.MoveNext
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253

    Re: Report in Grid or Grid type control

    Quote Originally Posted by ganeshmoorthy
    i guess i is for your column and j is for your row values
    VB Code:
    1. .TextMatrix(i, j) = Trim(adoRS.Fields(i).Value & "")
    TextMatrix takes row, column, but you have given col, row check it and then in the MoveNext statement you have given some different recordset name and you have checked in the Do while some different recordset name... Do While adoRs.EOF and adoPrimaryRS.MoveNext
    Don't be confused about the recordset name. I have used Col, Row to make the Row as Col and Col as Row in Grid display.

  16. #16
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Report in Grid or Grid type control

    VB Code:
    1. For j = 0 To adoRs.RecordCount -1
    2.         For i = 0 To adoRs.Fields.Count - 1
    3.             .TextMatrix(j+1, i+1) = adoRS.Fields(i).Value
    4.         Next i
    5.        adoRs.MoveNext
    6.     Next j
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253

    Re: Report in Grid or Grid type control

    Quote Originally Posted by ganeshmoorthy
    VB Code:
    1. For j = 0 To adoRs.RecordCount -1
    2.         For i = 0 To adoRs.Fields.Count - 1
    3.             .TextMatrix(j+1, i+1) = adoRS.Fields(i).Value
    4.         Next i
    5.        adoRs.MoveNext
    6.     Next j

    Thank you for your continuous help but sadly it didnot solve my problem. I think I will have find another control so something that display the data in GRID as I want.

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253

    Re: Report in Grid or Grid type control

    The code below gives the result close to my desire. It dispays the 1st record vertically in GRID but after that nothing happens though there are 5 rows. Means 'For i' statement is working but after displaying the 1st record it doesn't display the next record mean 'For j' not working.



    VB Code:
    1. With ManuRatioGrid
    2.  
    3. Do While Not adoPrimaryRS.EOF
    4.  
    5. For j = 0 To adoPrimaryRS.RecordCount - 1
    6.  
    7. For i = 0 To lngCol
    8.  
    9. .TextMatrix(i + 1, j) = Trim(adoPrimaryRS.Fields(i).Value & "")
    10.  
    11. Next i
    12.  
    13. adoPrimaryRS.MoveNext
    14.  
    15. Next j
    16.  
    17. Loop
    18. End With

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253

    Re: Report in Grid or Grid type control

    Any help on this plssssssss.

    Or can any one suggest any grid where I can display records in the following format.

    Year----2000
    Field1---100
    Field2---100
    Field3---100


    Thanks

  20. #20
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Report in Grid or Grid type control

    You just need to set the number of rows to the number of fields, and the number of columns to the number of records + 1 (field names). Then you fill the cells using (FieldNo,RecordNo), as the Textmatrix has parameters of (Row,Column).

    Here's the code:
    VB Code:
    1. Dim lngRow As Long, lngCol As Long
    2.  
    3.   If adoPrimaryRS.EOF Then     'check we have data
    4.     MsgBox "no data!"
    5.     ManuRatioGrid.Rows = 0
    6.   Else
    7.     With ManuRatioGrid
    8.       .Rows = adoPrimaryRS.Fields.Count
    9.       .Cols = 2
    10.       .FixedRows = 0
    11.       .FixedCols = 1
    12.                       'add field names
    13.       For lngRow = 0 To adoPrimaryRS.Fields.Count - 1
    14.         .TextMatrix(lngRow, 0) = adoPrimaryRS.Fields(lngRow).Name
    15.       Next lngRow
    16.      
    17.       lngCol = 1
    18.       Do While Not adoPrimaryRS.EOF
    19.                       'fill a column with a record
    20.         For lngRow = 0 To adoPrimaryRS.Fields.Count - 1
    21.           .TextMatrix(lngRow, lngCol) = (adoPrimaryRS.Fields(lngRow).Value & "")
    22.         Next lngRow
    23.                       'move on to next record
    24.         adoPrimaryRS.MoveNext
    25.         If Not adoPrimaryRS.EOF Then
    26.           .Cols = .Cols + 1
    27.           lngCol = lngCol + 1
    28.         End If
    29.       Loop
    30.     End With
    31.   End If

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253

    Re: Report in Grid or Grid type control

    Thanks Geek. It is working. Thank you very much.


    Quote Originally Posted by si_the_geek
    You just need to set the number of rows to the number of fields, and the number of columns to the number of records + 1 (field names). Then you fill the cells using (FieldNo,RecordNo), as the Textmatrix has parameters of (Row,Column).

    Here's the code:
    VB Code:
    1. Dim lngRow As Long, lngCol As Long
    2.  
    3.   If adoPrimaryRS.EOF Then     'check we have data
    4.     MsgBox "no data!"
    5.     ManuRatioGrid.Rows = 0
    6.   Else
    7.     With ManuRatioGrid
    8.       .Rows = adoPrimaryRS.Fields.Count
    9.       .Cols = 2
    10.       .FixedRows = 0
    11.       .FixedCols = 1
    12.                       'add field names
    13.       For lngRow = 0 To adoPrimaryRS.Fields.Count - 1
    14.         .TextMatrix(lngRow, 0) = adoPrimaryRS.Fields(lngRow).Name
    15.       Next lngRow
    16.      
    17.       lngCol = 1
    18.       Do While Not adoPrimaryRS.EOF
    19.                       'fill a column with a record
    20.         For lngRow = 0 To adoPrimaryRS.Fields.Count - 1
    21.           .TextMatrix(lngRow, lngCol) = (adoPrimaryRS.Fields(lngRow).Value & "")
    22.         Next lngRow
    23.                       'move on to next record
    24.         adoPrimaryRS.MoveNext
    25.         If Not adoPrimaryRS.EOF Then
    26.           .Cols = .Cols + 1
    27.           lngCol = lngCol + 1
    28.         End If
    29.       Loop
    30.     End With
    31.   End If

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