Solved

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

Posted on 2007-03-26
5
215 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 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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

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 …
This article will show, step by step, how to integrate R code into a R Sweave document
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

717 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