I have a command button on a word document that opens a user form for inputting values which are placed into a new row on a table. One of the columns on each row contains a checkbox. There is a second command button that, when clicked, deletes the rows that have checked check boxes. My problem is with this second command button; it does what it is supposed to in that it deletes the correct row, it just also happens to cause a run-time error. I know what block of code is causing the problem but I haven't got any ideas on how to resolve the problem.
Code:
Private Sub CommandButton2_Click()
Dim Answer As VbMsgBoxResult
Dim iRowCount As Integer
Dim oCtr As InlineShape
Dim iCounter As Integer
Dim iCheckCount As Integer
Dim strName As String
'Select the correct table and set the table variable
Answer = MsgBox("Are you sure you want to delete the checked items?", vbYesNo, "Confirm Deletion")
'Give the user a chance to cancel row deletion
iRowCount = Tables(1).Rows.Count - 2
'Don't count the first two rows (Title and column labels)
If (iRowCount < 1) Then
'Check if there are no data rows
MsgBox "There must be at least one item in the table to remove items", , "Error!"
'Provide feedback to user
End
End If
Select Case Answer
Case vbYes:
'Deletion Confirmed
'Must delete rows with checked "Completion" check boxes
For iCounter = 3 To iRowCount + 2
For iCheckCount = 1 To 10
strName = "CheckBox" + CStr(iCheckCount)
If (CheckExists(strName, iCounter)) Then
Set oCtr = ActiveDocument.Tables(1).Rows(iCounter).Cells(3).Range.InlineShapes(1)
If (oCtr.Field.OLEFormat.Object.Value) Then
ActiveDocument.Tables(1).Rows(iCounter).Delete
End If
End If
Next iCheckCount
Next iCounter
Case vbNo:
'Deletion Cancelled
'No action required
Case Else
'It is not possible to enter this section of code
MsgBox "Invalid Selection!"
End Select
End Sub
*EDIT - Of coarse as soon as I post this thread I figure out the problem; after deleting the row, it tries to do it again...9 more times*