creating our own template in VB

A

Associates

Hi,

I was wondering if i could get some help here. I was trying to set up a form
in word document which is then saved as a template. This is my first time
that i have attempted to do this. Thus, really need your guidance on this.

So, i have created a form in the word document using "forms" toolbar. After
finishing with the design, i then saved it as a template .dot. However, what
i would like to do here is instead of getting the user to type values
directly into the fields set in the document after running the template file,
I would like a pop-up form that would appear immediately when opening the
tempate. So the user will have to fill out the provided empty fields in the
form. Also there is a button called "generate report" in the pop-up form. By
clicking on the button, all the values from the fields will be dumped nicely
into the fields in the word document. hope i haven't lost you so far.

The following is the code i have that gives me a run-time error '5941' - The
requested member of the collection does not exist.

' Insert student's firstname (if any).
If (txtFirstName <> "") Then
ThisDocument.FormFields("StudApplication").Result = txtFirstName
Else
ThisDocument.FormFields("StudApplication").Delete
End If

How do i solve this error? BTW, how do i get into design mode in the word
document? because all the controls in the form toolbar are greyed out or
disable.

Thank you for your help in advance
 
R

Russ

Doug gave you the userform link.
I'll try to explain the error code.
Apparently when you run the code, you do not have a formfield with a name of
"StudApplication", so if you try to address it, specifically, as you are
doing in this code (even while testing for existence), the compiler
(mailman?) says 'no one at that address'.

So for some collections you must loop through all their elements first and
test with code like this pseudocode:

Dim aMember As Word.WhateverCollection
For each aMember of Activedocuments.WhateverCollections
If aMember.name like "StudApplication" then
...
Else
...
End If
Next aMember

Of course if you do already know that it exists then you can address it
specifically.
 

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