![]() |
|
|
|
#1
|
|||
|
|||
|
Hello, I have a docx (protected) when a user clicks a ckbox after tabbing out another automatically checks as well. Version two of the document I added more to the docx and made it landscape to accommodate the new column. The issue I am having is when i click on the new column ckbox and tab, the mirrored ckbox doesn't check like the other columns.
Her is what I run on exit: Code:
Sub MyMacro() Dim ffld As Word.FormField Dim rw As Row Set rw = Selection.Rows(1) rw.Cells(4).Range.FormFields(1).CheckBox.Value = rw.Cells(1).Range.FormFields(1).CheckBox.Value End Sub Last edited by macropod; 08-31-2012 at 05:54 PM. Reason: Added code tags |
|
#2
|
||||
|
||||
|
Hi coconutt,
The issue is that your macro is only designed to update the 4th column from the 1st column's result. Try: Code:
Sub MyMacro()
Application.ScreenUpdating = False
Dim TblRow As Long, TblCol As Long
With Selection
TblRow = .Cells(1).RowIndex
TblCol = .Cells(1).ColumnIndex
.Tables(1).Cell(TblRow, TblCol + 3).Range.FormFields(1).CheckBox.Value = _
.Tables(1).Cell(TblRow, TblCol).Range.FormFields(1).CheckBox.Value
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
That works, thank you so much.
|
|
#4
|
|||
|
|||
|
Thanks for the reply, when i use this code i get a run-time error 5941. The requested member of the collection does not exist. Any thoughts?
|
|
#5
|
||||
|
||||
|
You're probably calling the macro from a formfield it was never meant to be called from. It should only be called from checkbox formfields for which there is a corresponding checkbox formfield two columns to the right.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#6
|
|||
|
|||
|
hmm, I thought I had the correct ckBox form field? Please see attatched
|
|
#7
|
||||
|
||||
|
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
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
| Tags |
| word automation, word vba |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Document automation
|
coconutt | Word | 1 | 05-02-2012 01:45 PM |
| Automation Word-Excel | stephen_pen | Mail Merge | 0 | 09-22-2011 05:17 PM |
Urgent help regarding automation.
|
aligahk06 | Excel | 1 | 01-14-2010 01:55 PM |
| What is Application Automation and How can I use it in VBA | KramerJ | Excel | 0 | 03-30-2009 12:59 PM |
| COM Automation Errors | ivanm | Word | 0 | 03-23-2009 07:02 PM |