Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

adding a new line on user form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ScottP - 08 Mar 2005 20:54 GMT
I am creating a user form that is asking the user for
phone type (drop down) and then quantity.  I would LOVE
to be able to have "do you have another phone type"
yes/no IF yes create a new line for phone type and
quantity IF no goto the next field in the form.  How can
this be done?

BTW, I'm new so please do give me death by code.

Many thanks in advance.

ScottP
Doug Robbins - 09 Mar 2005 00:43 GMT
I assume that you are using formfields in a protected document.  If that is
the case, you may be able to make use of the following:

Sub addrow()

'

' Macro created 02/02/03 by Doug Robbins

' To add a new row to a table containing formfields in every column

' automatically on exit from the last cell in the present last row of the
table

Dim rownum As Integer, i As Integer

ActiveDocument.Unprotect

ActiveDocument.Tables(1).Rows.Add

rownum = ActiveDocument.Tables(1).Rows.Count

For i = 1 To ActiveDocument.Tables(1).Columns.Count

   ActiveDocument.FormFields.Add
Range:=ActiveDocument.Tables(1).Cell(rownum, i).Range,
Type:=wdFieldFormTextInput

Next i

ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count,
ActiveDocument.Tables(1).Columns.Count).Range.FormFields(1).ExitMacro =
"addrow"

ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count,
1).Range.FormFields(1).Select

ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

End Sub

The best way to implement it would by having a macro run on exit from the
present field that displayed a message box asking the question and then
incorporated code similar to the above if the answer is "Yes".  Check out
the MsgBox item in the Visual Basic Help file to get the syntax that you
need.

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

>I am creating a user form that is asking the user for
> phone type (drop down) and then quantity.  I would LOVE
[quoted text clipped - 8 lines]
>
> ScottP
ScottP - 09 Mar 2005 13:25 GMT
I have looked over your instructions and of course tried
to follow them close.  I have had an error and and have a
question.  First the error:

When I type this line:
Range:=ActiveDocument.Tables(1).Cell(rownum, i).Range,
I get an error at the := (expected.expression)

Question:
I've tried to pick this apart without wasting your time
but where in here to I put my fields names how does it
know it is adding rows to that table and not another tbl
that I've created?  I've seen nowhere that I can add a
name to the tbl.  Sorry for the trivial questions.

In case you need to get a better vision my fields are
simple, I have a 3 column table column 1 is SetType (pull
down with phone set models) column 2 is Qty (number
field) column 3 is addanotherset and is a checkbox.

Thanks again for sharing your knowledge!

ScottP
>-----Original Message-----
>I assume that you are using formfields in a protected document.  If that is
[quoted text clipped - 58 lines]
>
>.
Charles Kenyon - 09 Mar 2005 17:15 GMT
ActiveDocument.FormFields.Add
Range:=ActiveDocument.Tables(1).Cell(rownum, i).Range,
Type:=wdFieldFormTextInput

The above is all one line of the macro. You could add underscores if it is
to be split.

ActiveDocument.FormFields.Add _
Range:=ActiveDocument.Tables(1).Cell(rownum, i).Range, _
Type:=wdFieldFormTextInput

Signature

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.

>I have looked over your instructions and of course tried
> to follow them close.  I have had an error and and have a
[quoted text clipped - 103 lines]
>>
>>.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.