Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Checkbox made with Word 'Forms' toolbar - Newbie Question 1

Status
Not open for further replies.

theKeyper

Technical User
Jun 11, 2003
79
AU
Hello everyone,
sorry to bother you with such a Newbie question, I only have a very basic knowledge of VBA, so please bear with me. Baisically I have a pre-made template in Word 2000 which includes checkboxes of the variety made with the 'forms' toolbar. I have added a basic 'autonew' VBA form that puts text from txtfields into bookmarked positions in the template. I want to be able to have checkboxes on the form that will automatically set the checkboxes in the document. If someone could get back to me as soon as possible I would really appreciate it. Thanks alot.
-Keyper
 
Presuming this would fire from some button...

Sub CommandButton_Click()

''' other stuff as needed ''''

if chkNum1 = True then
ActiveDocument.Bookmarks("Check1").Result = True

End Sub

If the form checkbox (chkNum1) is True, then the document checkbox ("Bookmarks("Check1") is also True (checked).

Gerry
 
Thanks alot Gerry,
I tried this code:

Private Sub btnNext1_Click()
If chkVisual = True Then
ActiveDocument.Bookmarks("ServiceRequestedChk1").Result = True
End Sub

and came up with following error:

Compile Error: Method or data member not found

and it selected the '.result' part of the code. I know I have the spelling right, but what am I doing wrong?

I need to get this done very soon so I appreciate your geting back to me quickly. Thanks alot,
-Keyper
 
Result is a property of a Field or FormField object, not of a Bookmark one.
Another note: There is a lacking End If in your Sub.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks PH,
Stupid me, forgeting the end if, but I put it in and still the same error comes up. ("ServiceRequestedChk1") is the name of the bookmark I assigned to the FormField Checkbox in my document. Do I not refer to it by it's bookmark name? Or do I call/reference it by something else? Thanks alot for any insight. -Keyper

P.S. How do I comment out code so that It is readable but does not execute?

Rock on,
-Keyper.
 
O.K. tried again and I realised that I had to swap the .Bookmarks with .FormFields (Told you I was stupid). So I got everything compiling sweet. The thing is now, there are no errors or anything, but the check box in the document is not checked when it should be. Perhaps it is setting the value to true, but not actually showing the box to be checked? Is there different code for checking the box instead of just setting the value? or should that be done automatically? Rock on,
-Keyper
 
Try something like this:
ActiveDocument.FormFields("ServiceRequestedChk1").Result = chkVisual
' Comments here
' another comments

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks PH,
OK, I think the check boxes are not checking because the document has to protected for forms before the checks will show up. The thing is that when the document is protected the macros don't run. Any Advice??
-Keyper
 
Hi theKeyper,

The above mentioned sollutions don't work for me.

I use the Click Event of the checkbox with this code
Code:
Private Sub cbxKlik_Click()
    ActiveDocument.Unprotect Password:="jojo"

    With Selection.FormFields(1)
        .Name = "joost"
        .EntryMacro = ""
        .ExitMacro = ""
        .Enabled = True
        .OwnHelp = False
        .HelpText = ""
        .OwnStatus = False
        .StatusText = ""
        With .CheckBox
            .AutoSize = True
            .Size = 10
            .Default = True
        End With
    End With

    ActiveDocument.Protect Password:="jojo", NoReset:=False, Type:= _
        wdAllowOnlyFormFields

End Sub

You have to change the indexnumber of you're checkbox formfield mine is (1)
Joost is the name of the bookmark
jojo is the password!

There's probarbly some redundant code over there but it works.

Like you mentioned you need to remove the document protection before you can change the value of the checkbox made with the formstoolbar.

Enjoy.
 
Thanks JVerdaasdonk for that code, however you might have to explain that to me a bit more. what does a 'with/end with' statement do? and I don't think that is quite the code I am looking for. I have been playing around and I can't seem to get the checkbox to check weather the document is protected or not. The only way a check displays in the document is if I click on the checkbox while the document IS PROTECTED. I cannot get it to work with a macro. Just to clarify, I am simply trying to display a check on the document for printing purposes, I do not need the value for any other code. Is there a simpler way to do this? Thanks alot. I'm running out of time.
-Keyper
 
Hi theKeyper,

You don't have to check if the document is protected. It is, otherwise you're formfields would not be working.

The code mentioned above does remove the password for you and after checking the box it puts the password back.

You've been working on this for a while so I think it would be helpfull for you if I send you an example that works. (or you can send me you're template to modify)

If you send me an e-mail I'll send you an simple example:
(joostverdaasdonk[@]hotmail[.]com)

Please remove the brackets to use the adres.

Enjoy,
Joost Verdaasdonk
 
Just posting a thankyou to Joost for all his help and time, and baisicaly letting people know that problem has been fixed. Runs perfect Joost, I owe you one buddy. Thaks all for help,
-Keyper

PS. Kinda late I know but better late than never.
 
To the Dude,

Glad everything worked out well for you! (you happy I'm happy)

Enjoy,
Joost Verdaasdonk
 
theKeyper, thanks for sharing.
Can you please explain the members how you solved your problem ?
 
Hi PHV,

This is the code used to check a formfield from a Userform checkbox: (In TheKeyper his template)
Code:
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If chkSpecies1.Value = True Then
    With ActiveDocument.FormFields("chkSpecies1")
        With .CheckBox
        .Default = True
        End With
    End With
End If
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Enjoy,
Joost Verdaasdonk
 
Hi,
sorry about that PHV, and thanks Joost for replying for me. The other problem with the Form needing to be protected was solved by Joost in a previous post in this thread where he said:

Code:
Private Sub cbxKlik_Click()
    ActiveDocument.Unprotect Password:="jojo"
'
'(stuff)
'
    ActiveDocument.Protect Password:="jojo", NoReset:=False, Type:= _
        wdAllowOnlyFormFields

End Sub

Thanks Joost, and I hope this thread can help anyone with this problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top