Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selections in a grid

Status
Not open for further replies.

DriesG

Programmer
Jul 2, 2003
16
0
0
BE
Dear all,

I would like to make a delete query, based on the multiple selections from a vbalgrid.
I know a way to do this with a listbox:
you just create an "IN-string". For example

dim strIN as string
dim i as integer
For i = 0 To lstList1.ListCount - 1
If lstList1.Selected(i) Then
strIN = strIN & lstList1.Column(0, i) & ","
End If
Next i

The created IN-string can than be used in an SQL-string.

I don't know how to do this with a grid. You can get the information from a column in the grid through '.rowselected'
or through 'vbalGrid1.CellText(vbalGrid1.SelectedRow, 1)',
But that only gives the information about the current selected row. Not the other rowes that are selected as well.

Does anybody know how to do this?

Thank you very much,
Dries
 
Perhaps I have already a part of the solution:

Dim msg As String
Dim i As Integer
For i = 0 To dataSuppliers.Recordset.RecordCount - 1
If vbalGrid1.CellSelected(i, 3) Then
msg = msg & vbalGrid1.CellText(i, 1) & ","
End If
Next i

with the CellSelected method you can define if a cell or row is selected. If it is, the data from the cell in the first column from that row is the data I need.
This works great when I replace the i by a real value: for example 1.
When the i stays, I get the error message: Invalid Row Index. Although it is declared as an integer (or long, but that doesn't work as well).

Is there a way to let the code accept this i value?

Thanks,
Dries

 
OK,

I found the solution. Of course you should start the code as follows:
For i = 1 To dataSuppliers.Recordset.RecordCount
in stead of
For i = 0 To dataSuppliers.Recordset.RecordCount - 1

0 is not a valid row in a grid. The first row is of course row 1

Perhaps this information is usefull for other users as this question was raised before, but there were no real solutions.


Best regards,
Dries
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top