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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem completing a check box in Word97 from VB6

Status
Not open for further replies.

HaworthBantam

Programmer
Jan 31, 2002
132
GB
I have written a VB6 app that opens a Word97 template and automatically feeds data into it from an Access database.

Relevant sections of the code are below....

Set wdMyApp = New Word.Application
Set wdMyDoc = wdMyApp.Documents.Add([pathway to template here])

wdMyApp.Documents([filename here]).Activate

With wdMyApp
.ActiveDocument.Bookmarks("bkInjuredPerson").Select
.Selection.Text = frmViewAllRecords.txtViewAllName

The code goes on to select and complete various other bookmarks and all works fine until......

.ActiveDocument.FormFields("chkFemale").CheckBox.Value = True

This last particular line throws up an error......

5941 - The requested member of the collection does not exist.

The check box is a valid field within the template. I'm obviously missing something here and it wouldn't surprise me if it was something stupid. Any help you folks out there could give me would be most appreciated.
 

Although intuitively a Checkbox should take true and false, this is Microsoft! Their values are
vbChecked
vbUnchecked
vbGrayed

so use
.... Checkbox.Value = vbChecked Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
>>.ActiveDocument.FormFields("chkFemale").CheckBox.Value = True
>>
>>5941 - The requested member of the collection does not exist

have you checked the spelling of the field name?

if I had a copy of your document/template, I would loop through the FormFields collection and print each field's name

for i = 1 to .ActiveDocument.FormFields.Count
debug.print .ActiveDocument.FormFields(i).name
next
 
Thanks Justin,

Tried your sugestion and looped through the collection. The result showed that none of the check boxes that I've placed within the template are in the collection. I thought (wrongly) that they would have been automatically recognised.

The obvious question now is how do I add them to the templates' forms collection ?

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top