![]() |
#1
|
|||
|
|||
![]()
Hello Friends,
I am using a Form that was created thru MS Word and has several selection criteria in the form of check boxes. I want to add another check box that says select all. I need a macro that will look to about 15 checkboxes that I have labeled "LMSI_1 - LMSI_15" and check the boxes once the macro runs. Any ideas? I am using Office 2003. Thanks for any help provided! |
#2
|
||||
|
||||
![]()
Hi Johnny,
You could use an 'on exit' macro attached to the 'select all' checkbox, coded like: Code:
Sub CheckAll() Dim FrmFld As FormField, bChkAll As Boolean With ActiveDocument bChkAll = .FormFields("CheckAll").Result For Each FrmFld In .FormFields If FrmFld.Type = wdFieldFormCheckBox Then FrmFld.Result = bChkAll Next End With End Sub For something a little more sophisticated, you could use an 'on entry' macro as well to test the state of the checkbox before it is clicked, with code like the 'GetChkState' below: Code:
Dim bChkAll As Boolean Sub CheckAll() Dim FrmFld As FormField With ActiveDocument If .FormFields("CheckAll").Result = bChkAll Then Exit Sub bChkAll = .FormFields("CheckAll").Result For Each FrmFld In .FormFields If FrmFld.Type = wdFieldFormCheckBox Then FrmFld.Result = bChkAll Next End With End Sub Sub GetChkState() bChkAll = ActiveDocument.FormFields("CheckAll").Result End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
That worked out great!
I have another question, I have changed a few check Boxes to Form Fields with drop-down comments "Add" "Delete" and I was able to write the code that will mirror the comment from my Select all form field but I was only able to write it for one other individual bookmark, I have a range of form fields 1-15 labeled "LMSI_Office1 - LMSI_Office15" and I was not sure how to write that in code? Sub CopyField() Dim Temp As String Temp = ActiveDocument.FormFields("LMSI_Office1").Result ActiveDocument.FormFields("LMSI_Office2").Result = Temp End Sub Above is my code. I also need to add something to this and don't know how to do it, I need the code to un-protect the sheet before running the macro (No password required) and then re-protect the sheet "protect document for forms" Any idea's on the above question? The range question would really help out cause manually writing in 15 lines seems like overkill? Thanks for your help! |
#4
|
||||
|
||||
![]()
Hi Johnny,
Try: Code:
Sub CopyField() Dim StrResult As String, i As Integer With ActiveDocument StrResult = .FormFields("LMSI_Office1").Result For i = 2 To 15 .FormFields("LMSI_Office" & i).Result = StrResult Next End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
![]()
the macro worked out perfectly!!! Now how would I modify the code to say If I want to blank everything out again?
So my drop Down list has three criteria "Blank (empty form-field)" "Add", "Delete". |
#6
|
||||
|
||||
![]()
Hi Johnny,
Provided all the fields have the empty result option, you shouldn't need to change anything in the code - simply choose the empty result in the 'LMSI_Office1' formfield.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
![]()
I tried it and the only way I can get it to work is if I pu the macro "On exit" and after selecting blank scroll down to the next form-field and then the macro executes?
I am sending this form to people who don't follow directions well so I want to make it as user friendly as possible. Is there a way to put in the code after selecting blank the code will run the macro and then scroll down one form field? In excel I use the code FoundCell.Offset(1,1) to move down one cell from where the current postition is. Doesnt work in Word? |
#8
|
||||
|
||||
![]() Quote:
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
![]() Quote:
What I am trying to accomplish is, if a user gets the formand only needs to select all once and then save the sheet and send it back to me I don't want to tell them after selecting the formfield use tab or scroll down with the keyboard, I want it to happen automatically. And putting the macro "On entry" works but if the change the drop down to "Add" and then change there minds and put "delete" the macro doesnt run the second time. It just runs the "Add" all the way down? Do you know of any fixes? The way I was fixing it was unprotecting the sheet and then re-run the macro in VBA Editor but the user I send this too won't have access to unprotect? Im stuck... |
#10
|
||||
|
||||
![]() Quote:
Quote:
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
![]()
If I was to put the macro "On entry" once the macro runs if the user changes the drop down to another comment to have the macro re-run? I think maybe that was the question I should have asked.
When I do this now it seems like the macro will only run once? |
#12
|
||||
|
||||
![]()
No, that's not viable either. An 'On Entry' macro only runs when you enter the formfield, not while you're doing anything in it.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
![]()
I will try the method code you posted on the other post and see what I come up with.
Thanks again for all your help! |
![]() |
Tags |
macro, vba, word 2003 |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
karti | Word | 2 | 03-15-2011 06:06 AM |
Check whether Follow Up set | konfis | Outlook | 0 | 10-27-2010 11:19 PM |
Need Help with Using a Check Box | Nick9589 | Excel | 1 | 05-01-2010 09:29 AM |
Spell Check | WorkerB | Word | 2 | 11-21-2009 07:22 AM |
Check Box in Word | serayam | Word | 1 | 11-06-2008 06:45 AM |