Solved

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

Posted on 2007-03-26
5
210 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
  • 3
  • 2
5 Comments
 
LVL 13

Accepted Solution

by:
nike_golf earned 500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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 …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

839 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