[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • Last Modified:

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

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
itortu
Asked:
itortu
  • 3
  • 2
1 Solution
 
nike_golfCommented:
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
 
itortuAuthor Commented:
is a little bit confusing, sorry but could you explain it to me a little bit?
0
 
itortuAuthor Commented:
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
 
itortuAuthor Commented:
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
 
nike_golfCommented:
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now