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

Prompt user for input 1

Status
Not open for further replies.

Stretchwickster

Programmer
Apr 30, 2001
1,746
GB
I have been playing around with this for ages - the M$ help is not particularly helpful and I don't seem to be able to find any step-by-step instructions for what I'm trying to achieve, but please do point me in the direction of any links/articles that answer my query (I haven't been able to find them thus far!).

What I want to do is create a template which, when a new document is created from it, it prompts the user for various inputs via pop-up boxes (when the document is first opened) and then inserts the user responses into appropriate places in the document.

I've been playing around with Fields but have not been able to set them up properly, I've tried combinations of ASK and REF field codes (as directed by M$) but can't get them to stay on the page on a reload.

Could somebody please give me step-by-step instruction on how to do this, otherwise my full head of hair will soon be bald!!! ;-)

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Are these of any help?

faq68-5299 and faq68-5300
(Using FormFields In Word - Part 1 - Overview and Using FormFields in Word Part 2 – Coding with Form Fields

[tt]_____
[blue]-John[/blue][/tt]

"Patriotism is your conviction that this country is superior to all other countries because you were born in it."
[tab]-George Bernard Shaw

Help us help you. Please read FAQ181-2886 before posting.
 
I had already checked the FAQs here and looked at the ones you mentioned. However, Form Fields appear to be a facility whereby you can add an edit box, drop-down box or check-box to a document for the user to input into. The user can then choose when to enter data.

What I want is for a dialog box to appear requesting input from the user when a document is opened. I've seen a Word document where this has been setup and it was using some in-built Word functionality and not VBA macros/forms.

Clive
Runner_1HumanRedTop.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Anyone else know how to do this?

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Clive,
Not sure if this is relevant or will help any way, but I remember once, a good few years ago, seeing a template that when opened presented the user with a screen with a number of drop down boxes. When the user selected these and pressed enter, a document/letter was created, determined by the options chosen.

From what I recall it made use of user defined Autotext entries to insert the relevant bits. This may not be of help to you, as I'm fairly certain it used VBA to get the autoext entries into the document, but I thought I'd mention it if you haven't been down the autotext path.

Sadly, I've not got the template anymore, and can't remember exactly how it was done.

Hope this is of some help

Regards,
Marc
 
Lilliabeth, I had already tried that and last time it wasn't working correctly.

For those of you who wish to know how I got this to work, follow this process. It seemed to be the easiest way to get it working and to ensure the placeholders were visible on screen:
1) Create a new Word document
2) Write the document text into which you would like to add the user's input.
3) In the appropriate parts of the text, press <CTRL+F9> to insert a field code placeholder.
4) In each placeholder type FILLIN "Prompt", replacing the word "Prompt" with the text you wish the user to be prompted with.
5) Save the document as a Document Template (*.dot).
6) Double-click the file's icon and a new document based on that template will be opened and you will immediately be prompted as many times as you added a FILLIN field code.

Example
Code:
Hello, my name is [b]{[/b]FILLIN "Enter your name:"[b]}[/b] and I live at [b]{[/b]FILLIN "Enter your address:"[b]}[/b] with a pet called [b]{[/b]FILLIN "Enter your pet's name"[b]}[/b].

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Thanks for posting the solution Clive

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Incidentally, when you reopen the template you cannot see the placeholders you originally wrote yet they still work. Anyone know how to overcome that?

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
What you want is fairly easy to do.

You want a dialog form, whereby the user enters information, and then when finished, the forms inserts the information into the document. Correct?

If so, then what you are asking about is a UserForm. The userform has fields (either text entry, dropdowns, or checkboxes). Plus, of course, an OK button. Clicking the OK button simply has the form insert data from the form into either formfields, or bookmarks in the document.

In its simplest - as we can't post files here - here is a sample of what you can do. And this IS simple.

Take your document, and press Alt-F11 to get the Visual Basic Editor.

Press Ctrl-R to get the Project Explorer.

Highlight the project for your document, and then select Insert > Userform.

Expand the Forms "folder" in the Project Explorer, and then double click the empty form.

If the Toolbox is not showing, select View > Toolbox (can't remember the shortcut key for it....).

Select the Textbox icon on the Toolbox. Draw two textboxes on the form. Find the CommandButton icon. Select it and draw a commandbutton on the form.

In the Project Explorer select the LEFT-most button at the top. This is the View Code button.

In the code module that appears, select the left top dropdown, and pick Commandbutton1.

NOTE: all this is going to use the default names. I would strongly encourage you to make your own names. It is generally speaking NOT a good idea to accept default names.

Put the following code into the code for Commandbutton1 - that is, between Sub Commandbutton1_Click(), and End Sub.

Code:
Sub Commandbutton1_Click()
   Dim myFormfields As Word.FormFields
   Set myFormfields = ActiveDocument.FormFields
   myFormfields("Text1").Result = TextBox1.Text
   myFormfields("Text2").Result = TextBox2.Text
   Set myFormfields = Nothing
   Unload Me
End Sub

Next, select the ThisDocument code module for the document. You find it under Microsoft Word Objects in the Project Explorer for the the document. Double click to open.

Use the LEFT-most dropdown in the code module and select Document. The Document_New event appears in the code module. This is not what you want, so use the RIGHT-most dropdown to select Open. This makes a empty procedure for Document_Open. Put the following code there - betweeen Sub Document_Open() and End Sub. It shopuld look like:
Code:
Sub Document_Open()
  Userform1.Show
End Sub
Select the Save button on the menu bar, and then close the VBE. OK, now for the document.

In the document, put in two text formfields. Use the Forms toolbar View > Toolbars > Forms.

Again, for this exercise accept the default names, but later you should not do so. The default names of the text formfields will be Text1, and Text2 - which is being used for the code of the commandbutton.

Protect the document for forms: Tools > Protect document, and then select forms and press OK. Do not bother with a password - this is just to see what happens.

Save the document. Close it. Ppen it again. Your userform will display on document open. When the commandbutton is clicked, text entered into the textboxes
will go into the formfields.

Done.

All that being said, this is VERY VERY simple stuff. There are a lot of things that can make this better. For example:

The commandbutton will display "Commandbutton1" - obviously you will want to have it say "OK", or "Done". Use the Caption property to change....the caption.

There is no error checking on the text input.

Default names are used.

You may want to use Bookmarks rather than formfields, as formfields require document protect. This may be a good thing, or a not so good things.

And on and on and on, yadda yadda yadda.

Good luck!


Gerry
 
Thanks for your extensive reply Gerry. By profession, I'm a Delphi programmer, so I'm proficient at Rapid Application Development (RAD) and play around with forms everyday at work. I've also done a bit of Excel VBA and have created UserForms several times - but thanks for posting anyway - I must say I haven't played with Word's FormFields before though.

My question was more one of curiosity, I opened a document template which had prompts for user input and couldn't replicate it myself. VBA UserForms are obviously more suited to multiple user input, but I just wanted to understand how user input prompts in a template were implemented without using VBA.

Thanks once again.

Would it just be a case of adding bookmarks in order to see where the FILLIN placeholders were originally positioned?
I have tried this but after inserting a bookmark I still can't see it in the document.

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Darn, while I was typing the other response got in.

Using fields are good. The only problem is that using fields gives you one at a time. And if that is OK, then that is OK. But the advantage of a Userform is you can have multiple information entries on the same form. A textbox, a dropdown choice, a checkbox choice all on the same form. You can perform logic on them. Say if a dropdown choice is "Harry Belefonte" you can have "Yellow Bird" inserted any number of times, in any number of locations in the document. You can change other fields (controls) on the form. You can perform tests on the user input. You can take the input and insert it in many places at once.

You can display the document open form for specific users by testing the logon name. If it is user X then show the form, if it is user Y, do not. This could also be useful for, say, if it is user X, put user X's name into the footer - "Data entered by User X".

And on and on.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top