?
Solved

add rows to grid depending by the number of rows returned by query.

Posted on 2007-03-26
5
Medium Priority
?
222 Views
Last Modified: 2010-04-30
hoca can rows be added according to the number of rows returned by the query?

    If Not rstSelect Is Nothing Then
        If Not rstSelect.BOF And Not rstSelect.EOF Then
            Do While Not rstSelect.EOF
                 strSerialNumber = rstSelect![serial_number]
                grdSerialNumber.TextMatrix(totalRecs, 0) = strSerialNumber
                rstSelect.MoveNext
                totalRecs = totalRecs + 1
            Loop
        End If
    End If

I am getting an error for this line

grdSerialNumber.TextMatrix(totalRecs, 0) = strSerialNumber

becasue I set up the grid row property to 2 and I am getting more than that in return.
0
Comment
Question by:itortu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 13

Accepted Solution

by:
nike_golf earned 2000 total points
ID: 18795690
This might help.

    Do Until rs.EOF
        r = r + 1
        frmMain.flxResults.Rows = r + 1
        For c = 0 To rs.Fields.count - 1
            frmMain.flxResults.TextMatrix(r, c) = rs.Fields(c).Value
            ' See if we need to enlarge the column.
            new_wid = TextWidth(rs.Fields(c).Value)
            If col_wid(c) < new_wid Then col_wid(c) = new_wid
        Next c
        rs.MoveNext
    Loop

NG,
0
 

Author Comment

by:itortu
ID: 18795767
is a little bit confusing, sorry but could you explain it to me a little bit?
0
 

Author Comment

by:itortu
ID: 18795830
i changed it to this:

    If Not rstSelect Is Nothing Then
        If rstSelect.BOF And Not rstSelect.EOF Then
            Do While Not rstSelect.EOF
                r = r + 1
                grdSerialNumber.Rows = r + 1
                For c = 0 To rstSelect.Count - 1
                grdSerialNumber.TextMatrix(totalRecs, 0) = rstSelect![serial_number]
                Next c
                rstSelect.MoveNext
                totalRecs = totalRecs + 1
            Loop
        End If
    End If

but i get the error:

method or data member not found  ( rstSelect.Count )

i am on vb 6.0
0
 

Author Comment

by:itortu
ID: 18795975
ok i think i got it to work. thank you much.
please let me know if you see i can improve the way I am using your code snippet.

thank you.


    If Not rstSelect Is Nothing Then
        If Not rstSelect.BOF And Not rstSelect.EOF Then
            Do While Not rstSelect.EOF
                r = r + 1
                grdSerialNumber.Rows = r + 1
                For c = 0 To rstSelect.RecordCount - 1
                    strSerialNumber = rstSelect![serial_number]
                    grdSerialNumber.TextMatrix(totalRecs, 0) = strSerialNumber
                Next c
                rstSelect.MoveNext
                totalRecs = totalRecs + 1
            Loop
        End If
    End If
0
 
LVL 13

Expert Comment

by:nike_golf
ID: 18799615
Sorry, I just checked back in this morning. I'm glad you got it figured out.

You may not need to test for BOF unless the recordset is used in some other part of your source before you get to your loop. I think EOF would sufice, other than that it looks fine.

            Do While Not rstSelect.EOF
                r = r + 1
                grdSerialNumber.Rows = r + 1
                For c = 0 To rstSelect.RecordCount - 1
                    strSerialNumber = rstSelect![serial_number]
                    grdSerialNumber.TextMatrix(totalRecs, 0) = strSerialNumber
                Next c
                rstSelect.MoveNext
                totalRecs = totalRecs + 1
            Loop


NG,
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question