Solved

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

Posted on 2007-03-26
205 Views
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
Question by:itortu
• 3
• 2

LVL 13

Accepted Solution

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

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

Author Comment

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:

i am on vb 6.0
0

Author Comment

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

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

Question has a verified solution.

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

Suggested Solutions

mapBully challenge 6 114
Problem to event 3 78
Excel VBA, find a string in a column, update a cell 7 67
Create Files based on Cell Values in a Range in Excel 12 19
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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.