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

Word Form Field

Status
Not open for further replies.

rhoneyfi

MIS
Apr 8, 2002
200
US
I have created a form using Word 2002 that is a Sales Agreement. Basically, a user can enter in items a client purchases and then print out the doc for them to sign. Sometimes though (rarely), a doc will need five different signatures from the client. What I would like is for a drop down list at the top of the form to ask "how many signarures". The user could then choose 1,2,3,4,5. Depending on their choice, this would insert the appropriate number of signature lines onto the doc. I macro writing skills are pretty primitive. Thanks in advance for any help.
 

rhoneyfi,

I played around and came up with this idea. First, I started a new Word Template--If you want sales people to use the same form again and again, then a template will work better. Word will create a new document based on the template, but the template remains in tact, but you knew that :)

The template starts off with a dropdown box made from Word's "Forms" Toolbar. I named the dropdown "Signatures" and I set "Run macro on Exit:" to "FinishRoutine". But you wont' be able to set the Exit macro until it has been created. Details follow below.

I then created a Bookmark named "Signatures", positioned at the point in the document where I want the signature blocks to begin. I formatted the paragraph after "Signatures" Bookmark to create a tab at the 3" position from the left margin, and having an underscore leader. This makes line for your clients to sign on.

Next, I went into the Visual Basic Editor (Tools/Macros/Visual Basic Editor) and created a new module named "Module1". In that module, I added the following Visual Basic sub-routine, named "FinishRoutine()". I have tried to add comments so you can see what happens when this routine runs. FinishRoutine() will automatically run when the cursor leaves the "Signatures" dropdown box.

Note that, because a Word Form is protected, you must have code to unprotect before any changes can be made. The code then protects the document again at the end of the procedure.

Here's the sub-routine:

Public Sub FinishRoutine()

Dim sigs As Integer
Dim i As Integer

'Move cursor to the Signatures bookmark
ActiveDocument.Bookmarks("Signatures").Select

'Enter the chosen number of signature blocks in the dropdown.
'This assumes that the paragraph at the Signatures
'Bookmark has been setup with an underscore leader
'tab at 3" from the left margin. The tab provides
'the line for your customer to sign on.

'The sigs variable will equal the number in the dropdown box.
'Sigs must not equal "Signatures". The val() function coverts the string
'value in the dropdown to its numerical equivalent.
sigs = Val(ActiveDocument.FormFields("Signatures").Result)

'If the user skips the dropdown, and it still says
'"Signatures", then show error message, put cursor back"
'at the dropdown box, and quit this routine.
If sigs = "0" Then
MsgBox "Please select the number of signatures.", vbCritical, "Signatures?"
ActiveDocument.Bookmarks("Signatures").Select
Exit Sub
End If

'If a valid numerical value is given to sigs then we type a signature
'block "sigs" number of times at the position of the Signatures bookmark.

'But first, unprotect the document so that we can type...
ActiveDocument.Unprotect

'The For-Next structure repeats "sigs" times...
For i = 1 To sigs
With Selection
.TypeText Text:=vbTab
.TypeParagraph
.TypeText Text:=" Signature"
.TypeParagraph
.TypeParagraph
.TypeParagraph
.TypeParagraph
End With
Next i

'Signature blocks are in place, so re-protect the document for forms
'but do not reset values entered into any form fields.
ActiveDocument.Protect NoReset:=True, Type:=wdAllowOnlyFormFields

End Sub

That's it! You will, most likely want to massage the scheme to suit your individual needs, but this is the basic idea of how you might go about this task. This is just one of several ways you might approach the problem. I will try to e-mail my Word Template to you. Good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top