Template Form fill using check boxes in word

C

CS Hayes

I used a piece of code for automaticly filling in a document through a user
form. I now need the code to fill in form check boxes on my document. Can I
access these through code? If so, how?

sample code:
With ActiveDocument
.Bookmarks("customer").Range.InsertBefore customer
End with
If enclosingx = yes Then
ActiveDocument.Bookmarks("enclosingx") = yes
End If

The "with" statement works fine.

"Enclosingx" is a checkbox on the document, this piece of code does not work.
 
C

CS Hayes

I have a catch:

Sub UncheckIt()
**** oAutoTextUnchkBox.Insert Where:=Selection.Range****
End Sub

and:

Sub CheckIt()
Dim oBMs As Bookmarks
Dim oStr As String
Dim oRng As Word.Range
'ActiveDocument.Unprotect 'Activate this line if using a protected Word form
Set oBMs = ActiveDocument.Bookmarks
oStr = Selection.Bookmarks(1).Name
Set oRng = oBMs(oStr).Range
****ActiveDocument.AttachedTemplate.AutoTextEntries("CB").Insert
Where:=oRng****
oBMs.Add oStr, oRng
oRng.Font.Color = wdColorBlack
'ActiveDocument.Protect wdAllowOnlyFormFields, NoReset:=True 'Activate this
line as required.
End Sub

it freezes at the astericked line
--
Chris Hayes
Still a beginner


CS Hayes said:
yes, this is the answer I needed (and more!) thanks!
 
G

Greg Maxey

I don't really know what to tell you other than the code posted on my
website works and your code is different.

Did you download the template and observe how it works?
 
C

CS Hayes

1) you have a great site, thanks for your service to our country

2) yes, The first example is from the site:

Sub UncheckIt()
**** oAutoTextUnchkBox.Insert Where:=Selection.Range****
End Sub

This line, marked by astericks, is freezing.
 
G

Greg Maxey

Thanks. You are welcome. That service, almost 30 years worth, ends in about
150 days ;-)

Oh you mean in the Toggle Objects.zip template. I thought you were using
the Interactive Userform Checkboxes pages.

When you saying freezing, what does that mean? Are you getting a runtime
error? What does it say?

The AutoExec procdure in that template creates the relationship between the
AutoText entries and thier varialble names when Word executes (if the
ToggleObjects.dot file is in the start up directory). Did you try stepping
through the AutoExec procedure to ensure the relationships where formed?
 
C

CS Hayes

I think where I'm getting lost is that I am using 2003 and the example is for
2007. You have a page refferenced for 2003 but I can't tell where that ends
and I can resume with the code on the 2007 page.
 
L

Lisa

Sorr, I meant this line:
ActiveDocument.AttachedTemplate.AutoTextEntries("CB").Insert
Where Range:=oRng
 
G

Greg Maxey

You didn't answer my questions.

Send me website feedback requesting contact (that will provide me your
valid e-mail address). I will send yuo a .dot file that contains the
code and a working example.
 
C

CS Hayes

I'm not quite sure how to do "web site feedback" but my email is:
hayes.cs(remove this)@gmail.com

removing the (remove this)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top