Thread: [Solved] ckBox automation
View Single Post
 
Old 09-11-2012, 04:22 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi coconutt,

I added the macro I posted to your previous attachment and checked its performance on every checkox formfield. None of the checkboxes in column 1 or your added column 6 threw an error and the corresponding checkboxes in columns 4 and 9 updated correctly.

The only anomolies concerned items 1016, 1180 and 15610 at the bottom of the first column. There, I believe, none of the checkboxes should trigger the on-exit function - and all of the checkboxes should be enabled (allow manual update). However, some of those checkboxes do trigger the macro and some are not enabled. Triggering of the macro from a column other than 1 on those rows generates the error.

For those three rows, you could trigger the following macro from column1 (to ensure columns 3 & 4 are cleared if column 1 is cleared):
Code:
Sub ClearChks()
Application.ScreenUpdating = False
Dim TblRow As Long, TblCol As Long
With Selection
  TblRow = .Cells(1).RowIndex
  TblCol = .Cells(1).ColumnIndex
  If .Tables(1).Cell(TblRow, TblCol).Range.FormFields(1).CheckBox.Value = False Then
    .Tables(1).Cell(TblRow, TblCol + 3).Range.FormFields(1).CheckBox.Value = False
    .Tables(1).Cell(TblRow, TblCol + 4).Range.FormFields(1).CheckBox.Value = False
  End If
End With
Application.ScreenUpdating = True
End Sub
And, to ensure only one of the checkboxes in columns 3 & 4 on those rows can be checked (and even then, only if column 1 is checked):
Code:
Sub ExclusiveCheck()
Application.ScreenUpdating = False
Dim TblRow As Long, TblCol As Long, iOffset As Long
With Selection
  TblRow = .Cells(1).RowIndex
  TblCol = .Cells(1).ColumnIndex
  If .Tables(1).Cell(TblRow, 1).Range.FormFields(1).CheckBox.Value = False Then
    .Tables(1).Cell(TblRow, TblCol).Range.FormFields(1).CheckBox.Value = False
    Exit Sub
  End If
  If TblCol = 4 Then iOffset = 1 Else iOffset = -1
  .Tables(1).Cell(TblRow, TblCol + iOffset).Range.FormFields(1).CheckBox.Value = _
    Not .Tables(1).Cell(TblRow, TblCol).Range.FormFields(1).CheckBox.Value
End With
Application.ScreenUpdating = True
End Sub
See attached.
Attached Files
File Type: zip LabOrder.zip (43.8 KB, 14 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote