?
Solved

VB6 DataGrid Going through Rows on Grid errors on last row

Posted on 2005-02-28
5
Medium Priority
?
2,835 Views
Last Modified: 2010-05-18
I have a bound Datagrid to an Access Db. In this particular case I get
an error when going through the rows to update a particular column.
The "resale" column is a hidden column. If I get a dataset with let's
say 9 rows, this will bomp out on the Datagrid1.Row when it i gets
to 8. This will udpate all rows except the last one. I have tried
For i = 1 To DataGrid1.ApproxCount -1
For i = 0 To DataGrid1.ApproxCount
For i =1 To DataGrid1.ApproxCount

            For i = 0 To DataGrid1.ApproxCount - 1
                DataGrid1.Row = i
                DataGrid1.Columns("resale") = i
                Debug.Print CStr(i) + "  " + DataGrid1.Columns(0).Text
            Next i

I have VB6 SP5 installed. Any help appreciated.
0
Comment
Question by:Tuftco
[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
  • 2
  • 2
5 Comments
 
LVL 13

Expert Comment

by:Michael_D
ID: 13423271
Hi Tuftco,

Instead of .ApproxCount property use your recordset's .RecordCount property

Cheers!
0
 

Author Comment

by:Tuftco
ID: 13423341
Either way, there is exactly 9 records to deal with in this case. What is getting me is that
the Datagrid seems to think that it has one less than what ever I return as a dataset.

0
 
LVL 13

Expert Comment

by:Michael_D
ID: 13423348
Dim i As Long
For i = 0 To myRecordset.RecordCount - 1
'For i = 0 To Adodc1.Recordset.RecordCount - 1 'if you are using adoDC component use this  line instead of prev one
    DataGrid1.Row = i
    DataGrid1.Columns("resale") = i
    Debug.Print CStr(i) + "  " + DataGrid1.Columns(0).Text
Next i
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 1000 total points
ID: 13427881
I have had problems with that too in the past. It seems that only visible rows are considered!

Try this:

           GridGotoTop

            For i = 0 To DataGrid1.ApproxCount - 1
                DataGrid1.Columns("resale") = i
                Debug.Print CStr(i) + "  " + DataGrid1.Columns(0).Text

           On Error Resume Next
           DataGrid1.Row = DataGrid1.Row + 1 'Set the active row
           On Error GoTo 0

            Next i


Private Sub GridGotoTop()
    With DataGrid1
        If .VisibleRows < .ApproxCount Then
            On Error Resume Next
            Do While .FirstRow <> 1
                .Scroll 0, -10
                .FirstRow = 0
            Loop
            On Error GoTo 0
        End If
        .Col = 0
        .Row = 0
    End With
End Sub
0
 

Author Comment

by:Tuftco
ID: 13455835
emoreau


Thank You for this answer. At first I didn't see why it works, but after a few trials I understand it.
I even used it go return to the top of the grid after going through the rows and updating
columns and making calculations..

GridGotoTop
With DataGrid1
  .Row = 0
  .Col = 0
End With

Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

777 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