Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
|
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 20th, 2006, 01:43 PM
Registered User
 
Join Date: Nov 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using Checkboxes in Word

I'm wondering if someone out there can help me with my code. I have written a code that is supposed to determine if a checkbox has been checked in the document, then add 1 to the counter. It has been a few years since I tried to write any sort of code, so I have a feeling my problem may be relatively simple. I get a runtime error 438 when I try and run the code.

Sub addcheck()

Dim counter As Integer

counter = 0
With ActiveDocument
    If .formfieldscheck1066.Checked = True Then
    counter = counter + 1
    End If
    If .FormFieldscheck1070.Result = True Then
    counter = counter + 1
    End If
    If .FormFieldscheck1074.Result = True Then
    counter = counter + 1
    End If


.formfieldstext819.Result = counter

End With

End Sub


Thanks!
 
Old November 20th, 2006, 10:03 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

Try

If .FormFields("check1066").Result = True
  counter = counter +1
End if

This Should work

Cheers
Shasur

http://www.vbadud.blogspot.com
 
Old November 22nd, 2006, 11:14 AM
Authorized User
 
Join Date: Nov 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

your problem is you need to reference the checkbox itself, (.checked is a property of the checkbox object)

ex

if chkCheckboxName.Checked = True Then
    counter = counter + 1
End If
 
Old December 29th, 2006, 03:57 AM
GLM GLM is offline
Authorized User
 
Join Date: Dec 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

if you use Rsult compare it to 1/0
other way
.FormFields("Name").ChekBox.Value - returns True/False

glm





Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating word doc - word behaviour mat41 Classic ASP Professional 2 April 29th, 2007 06:46 PM
2 sets of Checkboxes DJmoYst BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 June 7th, 2006 01:49 PM
Copy word to word doc. in VB vamshi Pro VB 6 1 March 24th, 2004 06:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.