ClimoC
Well-known Member
- Joined
- Aug 21, 2009
- Messages
- 584
My Query Table has a 'catchdelete' (Onkey) sub that determines if the whole row is selected. If it is, it looks up the ID in the table and sends the SQL command to remove the record. If it's not the entirerow, it resumes 'clearcontents'. Simple Right?
But I'd like this to work for multiple rows.
As there is no 'selected' boolean property for the 'EntireRow' range object, can anyone think of a way to basically do this?:
Code:
Public Sub CaughtDelete()
If cnImportConn Is Nothing Then Run "ActivateConn"
If Selection.Address = ActiveCell.EntireRow.Address Then
iD = Cells(ActiveCell.Row, 2).Value
strsql = "DELETE * FROM [work] WHERE ID = " & iD
cnImportConn.Execute (strsql)
Else
Selection.ClearContents
End If
End Sub
But I'd like this to work for multiple rows.
As there is no 'selected' boolean property for the 'EntireRow' range object, can anyone think of a way to basically do this?:
Code:
If cnImportConn Is Nothing Then Run "ActivateConn"
If Selection.Rows.Count > 1 Then 'this is fine - a valid statement
For Each r In Selection.Rows
If Cells(r.Row, 2).EntireRow.Selected Then 'here's the test I need to perform
iD = Cells(r, 2).Value
strsql = "DELETE * FROM [work] WHERE ID = " & iD
cnImportConn.Execute (strsql)
Else
Selection.ClearContents
End If
Next
End If
End If