Help with a macro in Word 2010


i have inherited a form created a macro-enabled template in word 2003.  form contained form fields , upon completing form, user clicked command button prompted user id, password, , added date stamp. locked form , kept form fields being edited.  there second command button when clicked prompted user for password used lock form.  if entered password matched original, form fields edited.

i have had add date picker , change legacy drop-down form fields drop-down list content cotrols due need more 25 listings in drop-down boxes , have done in word 2010.

my issue macro locks form fields to editing, not lock content controls.  need macro keep both form fields , content controls being edited second macro open both form fields , content controls being edited.

i know little vba , appreciate help. here macros written:

private sub commandbutton2_click()
dim pw
dim pwb
pw = me.pw.value
pwb = inputbox("please enter password used sign document.", "unlock document")

if pw = pwb then
msgbox ("this document has been unlocked editing.  please resign document lock before submission.")
me.commandbutton3.enabled = true
me.commandbutton2.enabled = false
me.pref_id = ""
me.pw = ""
me.dt = ""
dim ofmfld formfield
activedocument
each ofmfld in .formfields
ofmfld.enabled = true
next
end with

else
msgbox ("the password entered not match value on form.")
exit sub
end if
end sub

private sub commandbutton3_click()
dim pref
dim datestamp
datestamp = now
pref = inputbox("please enter preferred id lock document.", "electonic signature")
if pref = "" then
me.pref_id = ""
me.dt = ""
me.commandbutton2.enabled = false
msgbox ("preferred id required sign document.")
exit sub
end if

dim pw
pw = inputbox("please provide password lock document.", "enter password")
if pw = "" then
me.pref_id = ""
me.dt = ""
me.pw = ""
msgbox ("a password required")
me.commandbutton2.enabled = false
exit sub

else

me.pref_id = pref
me.pw = pw
me.pw.passwordchar = "*"
me.dt = datestamp

dim ofmfld formfield
activedocument
each ofmfld in .formfields
ofmfld.enabled = false
next
end with
me.commandbutton2.enabled = true
me.commandbutton3.enabled = false

end if
end sub

 

as said, changes suggested not related error message. perhaps problem did not implement them correctly. code should read:

private sub commandbutton2_click()
    dim pw
    dim pwb
    pw = me.pw.value
    pwb = inputbox("please enter password used sign document.", "unlock document")
    if pw = pwb then
        msgbox ("this document has been unlocked editing.  please resign document lock before submission.")
        me.commandbutton3.enabled = true
        me.commandbutton2.enabled = false
        me.pref_id = ""
        me.pw = ""
        me.dt = ""
        dim ofmfld formfield, cctrl contentcontrol
        activedocument
            each ofmfld in .formfields
                ofmfld.enabled = true
            next
            each cctrl in .contentcontrols
                cctrl.lockcontentcontrol = true
            next
        end with
    else
        msgbox ("the password entered not match value on form.")
        exit sub
    end if
end sub

private sub commandbutton3_click()
    dim pref
    dim datestamp
    datestamp = now
    pref = inputbox("please enter preferred id lock document.", "electonic signature")
    if pref = "" then
        me.pref_id = ""
        me.dt = ""
        me.commandbutton2.enabled = false
        msgbox ("preferred id required sign document.")
        exit sub
    end if
    dim pw
    pw = inputbox("please provide password lock document.", "enter password")
    if pw = "" then
        me.pref_id = ""
        me.dt = ""
        me.pw = ""
        msgbox ("a password required")
        me.commandbutton2.enabled = false
        exit sub
    else
        me.pref_id = pref
        me.pw = pw
        me.pw.passwordchar = "*"
        me.dt = datestamp
        dim ofmfld formfield, cctrl contentcontrol
        activedocument
            each ofmfld in .formfields
                ofmfld.enabled = false
            next
            each cctrl in .contentcontrols
                cctrl.lockcontentcontrol = false
            next
        end with
        me.commandbutton2.enabled = true
        me.commandbutton3.enabled = false
    end if
end sub


cheers
paul edstein
[ms mvp - word]



Microsoft Office  >  Word IT Pro Discussions



Comments

Popular posts from this blog

2008 Windows Deployment Server Properties Error

Can no longer user MS Update - Files required to use Microsoft Update are no longer registered

How do a find data in one file, search for it in another file and if not found, write a custom message to another file