Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-24-2012, 08:08 AM
dice1976 dice1976 is offline Macro ? - Checkbox in Word + drop down selection help Windows 7 32bit Macro ? - Checkbox in Word + drop down selection help Office 2010 32bit
Novice
Macro ? - Checkbox in Word + drop down selection help
 
Join Date: Jul 2012
Posts: 3
dice1976 is on a distinguished road
Question Macro ? - Checkbox in Word + drop down selection help

Hello,



I have been trying to create a macro for a form I have. I have a checkbox that I want to activate a drop down list when the checkbox is 'ticked' off.

The word document is protected so no one can change what is in the drop down selection or any item that is in the page.

I am uploading 2 pictures to briefly help understand what I am trying to do.

I hope someone can assist with this. It's been bothering me for months.

Thanks
Attached Images
File Type: png pre-dropdown.png (1.9 KB, 39 views)
File Type: png aftercheck.png (11.4 KB, 36 views)
Reply With Quote
  #2  
Old 07-24-2012, 09:58 AM
Charles Kenyon Charles Kenyon is offline Macro ? - Checkbox in Word + drop down selection help Windows Vista Macro ? - Checkbox in Word + drop down selection help Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,083
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

To better define your question:
If someone clicks in the Institution box you want to activate a drop-down? (or)
If someone clicks in the Institution box you want the choices to all appear as a part of the document?

Are your fields legacy form fields (those designed for protected documents) or the new content control fields?

I am assuming you have macros enabled.
Assuming these are legacy form fields, the field with your drop-down needs to have a name set in the properties to use in your macro.
Reply With Quote
  #3  
Old 07-24-2012, 10:08 AM
dice1976 dice1976 is offline Macro ? - Checkbox in Word + drop down selection help Windows 7 32bit Macro ? - Checkbox in Word + drop down selection help Office 2010 32bit
Novice
Macro ? - Checkbox in Word + drop down selection help
 
Join Date: Jul 2012
Posts: 3
dice1976 is on a distinguished road
Default

The document is "protected".

I would like to force the user if he checks the Insitution box that it activates the drop down and they have to make a selection (something other than "please choose cdb category here" the default)

The fields can have new content that controls the field - but for the drop box it is by selection only, and the check box can be checked or unchecked. By default it is unchecked.

I have macros enabled and I would like to use the "run macro on" Entry (checkbox select drop down) and on Exit (after drop down is selected)
Reply With Quote
  #4  
Old 07-24-2012, 10:32 AM
Charles Kenyon Charles Kenyon is offline Macro ? - Checkbox in Word + drop down selection help Windows Vista Macro ? - Checkbox in Word + drop down selection help Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,083
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Are your fields
  • legacy form fields (those designed for protected documents)?
  • or the new content control fields?
  • or active X controls?

You want legacy form fields.

You want an on-exit macro for the checkbox to enable the drop-down.

What follows is code that I use in a protected document to enable/disable a field depending on the value of a checkbox.

Code:
Option Explicit
Public sPass
' Module and Project Written by Charles Kyle Kenyon
' May 2001, Copyright 2001 All rights reserved

Sub AutoNew()
    AutoOpen
End Sub

Sub AutoOpen()
    SetDocumentVariablePassword
    sPass = ActiveDocument.Variables("FormPassWord")
    LockDocForForms 'Lock this form so formfields will work
    GoToStartingField 'If set for particular case, goto witness info
End Sub

Private Sub LockDocForForms()
    'Locks Document or Template for Forms upon opening or creation
    If ActiveDocument.ProtectionType <> wdAllowOnlyFormFields Then
        ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
            NoReset:=True, Password:=sPass
    End If
End Sub

Private Sub GoToStartingField()
    ' Checks to see if form has been modified for a particular _
        defendant. If it has, then start with Witness name, _
        otherwise, start with County name
    If ActiveDocument.FormFields("DefName").Result = "DEFENDANT'S NAME?" Then
        ActiveDocument.FormFields("County").Select
    Else
        ActiveDocument.FormFields("WitName").Select
    End If
End Sub

Private Sub SetDocumentVariablePassword()
    Dim num As Integer, aVar As Variable
    For Each aVar In ActiveDocument.Variables
        If aVar.Name = "FormPassWord" Then num = aVar.Index 'End If
    Next aVar
    If num = 0 Then
        ActiveDocument.Variables.Add Name:="FormPassWord", Value:="GF126"
    Else
        ActiveDocument.Variables(num).Value = "GF126"
    End If
End Sub

Public Sub ProtectSubpoenaForForms()
    On Error GoTo NotSubpoena
    With ActiveDocument
        sPass = .Variables("FormPassWord") 'will trip error message if not set
        If .ProtectionType = wdNoProtection Then .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=sPass
            ' End If
    End With
    On Error GoTo 0
    End
NotSubpoena:
    MsgBox "This is not a subpoena form based on the right template!", vbExclamation, "Oh! Oh! Wrong Document for this macro!"
End Sub

Sub DucesTecum()
'
' DucesTecum Macro
' OnExit macro for DucesTecum Checkbox
' "&chr(10)&"Macro recorded 05/16/2001 by Charles Kyle Kenyon
'
    Dim strBringWith As String, rRange As Range
    With ActiveDocument
        UnProtectSubpoena  'subroutine below
        Set rRange = .Bookmarks("YouBringYes").Range
        'Save result of form field
        strBringWith = .FormFields("BringWhat").Result
        If .FormFields("chkDucesTecum").CheckBox.Value _
            = True Then
            .FormFields("DucesTecumTitle").TextInput.EditType _
                Type:=wdRegularText, Default:=" Duces Tecum "
            If strBringWith = "" Then strBringWith = _
                "Bring what?" 'End If
            .FormFields("BringWhat").TextInput.EditType _
                Type:=wdRegularText, Default:=strBringWith, _
                    Enabled:=True
            rRange.Font.DoubleStrikeThrough = False
            rRange.Font.Bold = True
            .FormFields("BringWhat").Select
        Else
            .FormFields("DucesTecumTitle").TextInput.EditType _
                Type:=wdRegularText, Default:=" ", Enabled:=False
            .FormFields("BringWhat").TextInput.EditType _
                Type:=wdRegularText, Default:="", Enabled:=False
            rRange.Font.DoubleStrikeThrough = True
            rRange.Font.Bold = False
            .FormFields("chkThirdParty").Select
        End If
        .Protect wdAllowOnlyFormFields, True, sPass
    End With
End Sub
Sub ThirdParty()
'
' ThirdParty Macro
' OnExit Macro for Third-Party Checkbox
' "&chr(10)&"Macro written 05/16/2001 by Charles Kyle Kenyon
'
    Dim rRange As Range
    With ActiveDocument
        UnProtectSubpoena 'subroutine below
        Set rRange = .Bookmarks("ThirdPartyLanguage").Range
        rRange.Font.DoubleStrikeThrough = _
            Not .FormFields("chkThirdParty").CheckBox.Value
        rRange.Font.Bold = _
            .FormFields("chkThirdParty").CheckBox.Value
        .Protect wdAllowOnlyFormFields, True, sPass
    End With
End Sub

Sub UnprotectSubpoenaForm() 'For Menu
    MsgBox "The password to unprotect this document is " _
        & ActiveDocument.Variables("FormPassWord") & "." & vbCrLf _
        & "You must use the same password if you reprotect it, otherwise the form will not work. Please write it down.", vbExclamation, "Subpoena Form Password Information"
    UnProtectSubpoena
End Sub

Private Sub UnProtectSubpoena() 'Subroutine for other procedures
    With ActiveDocument
        sPass = .Variables("FormPassWord")
        If .ProtectionType <> wdNoProtection Then .Unprotect (sPass)
        ' End If
    End With
End Sub
This may be more than you need, but as you can see, I wrote this more than ten years ago. I don't code for this often.
It includes code for:
  • using a document variable for the password
  • unprotecting the document using the password
  • enabling/disabling a named field
  • altering formatting
  • and reprotecting a document without resetting field contents.

The procedures set as on-exit macros are labelled as such in comments. I hope this will help.
Reply With Quote
  #5  
Old 07-24-2012, 11:18 AM
dice1976 dice1976 is offline Macro ? - Checkbox in Word + drop down selection help Windows 7 32bit Macro ? - Checkbox in Word + drop down selection help Office 2010 32bit
Novice
Macro ? - Checkbox in Word + drop down selection help
 
Join Date: Jul 2012
Posts: 3
dice1976 is on a distinguished road
Default

Wow! Thanks Charles. This is definitely way more than I need (and very impressive).

I am not a total expert on macros in Word (I normally do excel ones, and usually not VB ones either). So as I do understand some of the code and what it is trying to do, I am a bit lost on how to assign the macro to the check box and how to assign the "pop up" to the drop down list.

Also note, I actually have 2 check boxes with 2 drop down lists, but only one can be checked off at a given time and never both.

Would it be easier if I uploaded the word doc for review?
Reply With Quote
Reply

Tags
checkbox, drop down, macro

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to calculate a value of a checkbox. stephen_ Excel Programming 1 06-27-2012 04:57 PM
Macro ? - Checkbox in Word + drop down selection help Limiting a macro to a selection Ulodesk Word VBA 4 06-19-2012 06:09 AM
Ho to perform multi selection in drop down lists? nashville Word 0 09-29-2010 07:10 AM
Macro ? - Checkbox in Word + drop down selection help Form Field - Drop down selection causing auto text chesspupil Word VBA 7 05-09-2010 05:43 AM
macro on checkbox macrohelp Word VBA 0 03-06-2009 03:33 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:40 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft