Command button in form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am creating a form template for users to fill out in word. In one section the user enters the name, address, phone, title, etc. of a group participant. This is set up as form fields in a table. I would like to include a command button for the user to click if they would like to enter another participant and this would add the additional lines and fields into the form. But because some users may only want one participant listed and some may need multiple participants, I want the option to appear after each entry is made.

Is this possible? Will it be possible when the form is locked?
 
It is possible, although I would use a macrobutton field instead of a
Command button. You can make a macrobutton field look like a command button
if you like. I would put it just under your table. Your macro unlocks the
form and inserts another row in your table with suitable fields, reprotects
the form, without resetting contents, and goes to the (new) next field. It
is probably easiest to insert the new row using AutoText which can contain
both the row and the fields. You may need different macros for different
versions of Word.

What you are talking about is what Word calls an "online form." For more
about online forms, follow the links at
http://addbalance.com/word/wordwebresources.htm#Forms or
http://word.mvps.org/FAQs/Customization/FillinTheBlanks.htm especially Dian
Chapman's series of articles.

Hope this helps,
--

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

als0107 said:
I am creating a form template for users to fill out in word. In one
section the user enters the name, address, phone, title, etc. of a group
participant. This is set up as form fields in a table. I would like to
include a command button for the user to click if they would like to enter
another participant and this would add the additional lines and fields into
the form. But because some users may only want one participant listed and
some may need multiple participants, I want the option to appear after each
entry is made.
 
Thank you for the suggestion. Just one question....how to have the macro reprotect the form without resetting the contents? I can't figure this out
THank you again for your time.
 
Thank you, I will try it now. What I had for the macro was this

ActiveDocument.Unprotec
Selection.MoveRight Unit:=wdCharacter, Count:=
Selection.MoveRight Unit:=wdCel
Selection.MoveRight Unit:=wdCel
Selection.FormFields.Add Range:=Selection.Range, Type:=
wdFieldFormTextInpu
ActiveDocument.Protect wdAllowOnlyFormFields, Tru

End Su

And it is not working...any thoughts?
 
Try using the LockUnlockFormToggle instead of your unprotect and protect
commands in your macro:

Sub LockUnlockFormToggle()
' Toggle macro to protect / unprotect form
' Written by Charles Kenyon
Dim oDoc As Document
Set oDoc = ActiveDocument
If oDoc.ProtectionType <> wdNoProtection Then
oDoc.Unprotect
Else
If oDoc.ProtectionType = wdNoProtection Then
oDoc.Protect _
Type:=wdAllowOnlyFormFields, _
NoReset:=True
End If
End If
End Sub

--

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
Please forgive my ignorance, but I have no idea what I am supposed to do with this. Do I Type all of it at the beginning of the macro?

The problem with the macro seems to be the third line. I think this is where I highlighted the part to copy

Any thoughts
Thank you so much for your help. I am really lost as to how to do this
 
I haven't tested your code. I am suggesting, that with the macros I sent you
also in your module,

UnProtectDocumentMacro
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
ProtectDocumentMacro

I put fields or table rows into AutoText and insert the AutoText instead of
trying to create fields on the fly. If I want to change the fields, I change
the AutoText manually. Perhaps a kludge but it works for me. What follows is
from a protected form that has different tables that have different kinds of
information and use some different fields. It is to insert a new row above
the current row (forgot to put something in the proper order and want to fix
it). It shows how to insert the AutoText. Maybe this will be of help for
you.

Sub InsertRowAboveMe()
'
' InsertRowAboveMe Macro
' Macro written 12/01/03 by Charles Kyle Kenyon
'
' Unprotect document
UnprotectDocumentMacro
'
'
Dim sAutoTextEntry1 As String
Dim sAutoTextEntry2 As String
Dim oTemplate As Template
Set oTemplate = Templates(ThisDocument.FullName)
'
With Selection
.SelectRow
' Test for Table 2
' -------------------------Table 2 - Time -----------------
If ActiveDocument.Range(0,
Selection.Tables(1).Range.End).Tables.Count = 2 Then
' Test for time row (4 columns)
If .Columns.Count = 4 Then
'
'' Add row if in a table
' If Selection.Information(wdWithInTable) = True Then
' Selection.Rows.Add BeforeRow:=Selection.Rows(1)
' End If
.InsertRows 1
.HomeKey Unit:=wdLine
Application.DisplayAutoCompleteTips = True
With AutoCorrect
.CorrectInitialCaps = True
.CorrectSentenceCaps = True
.CorrectDays = True
.CorrectCapsLock = True
.ReplaceText = True
End With
oTemplate.AutoTextEntries("zDateField").Insert Where _
:=.Range
.MoveRight Unit:=wdCell
oTemplate.AutoTextEntries("zTimeDescription").Insert _
Where:=.Range
.MoveRight Unit:=wdCell
oTemplate.AutoTextEntries("zTimeOutOfCourt").Insert _
Where:=.Range
.MoveRight Unit:=wdCell
oTemplate.AutoTextEntries("zTimeInCourt").Insert _
Where:=.Range
.MoveLeft Unit:=wdCell
.MoveLeft Unit:=wdCell
.MoveLeft Unit:=wdCell
End If ' 4 Columns
End If ' Table 2
'
' Test for Table 3
' -------------------------Tables 3 & 4 -
Disbursements ----------------------
If ActiveDocument.Range(0,
Selection.Tables(1).Range.End).Tables.Count > 2 Then
If ActiveDocument.Range(0,
Selection.Tables(1).Range.End).Tables.Count = 3 Then
sAutoTextEntry1 = "zExpenseDescription"
sAutoTextEntry2 = "zExpenseAmount"
Else ' Table 4 - Payments
sAutoTextEntry1 = "zPaymentDescription"
sAutoTextEntry2 = "zPaymentAmount"
End If
' Test for entry row (3 columns)
If .Columns.Count = 3 Then
'
'' Add row if in a table
' If Selection.Information(wdWithInTable) = True Then
' Selection.Rows.Add BeforeRow:=Selection.Rows(1)
' End If
.InsertRows 1
.HomeKey Unit:=wdLine
Application.DisplayAutoCompleteTips = True
With AutoCorrect
.CorrectInitialCaps = True
.CorrectSentenceCaps = True
.CorrectDays = True
.CorrectCapsLock = True
.ReplaceText = True
End With
oTemplate.AutoTextEntries("zDateField").Insert Where _
:=.Range
.MoveRight Unit:=wdCell
oTemplate.AutoTextEntries(sAutoTextEntry1).Insert _
Where:=.Range
.MoveRight Unit:=wdCell
oTemplate.AutoTextEntries(sAutoTextEntry2).Insert _
Where:=.Range
.MoveLeft Unit:=wdCell
.MoveLeft Unit:=wdCell
End If ' 3 Columns
End If ' Table 3

End With ' Selection
ProtectDocumentMacro
End Sub

Hope this is of some help.
--

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

als0107 said:
Please forgive my ignorance, but I have no idea what I am supposed to do
with this. Do I Type all of it at the beginning of the macro?
The problem with the macro seems to be the third line. I think this is
where I highlighted the part to copy.
 
Back
Top