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 / September 2006

Tip: Looking for answers? Try searching our database.

Word Form Fields & Macros

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
LPS - 26 Sep 2006 15:56 GMT
Working with Word 2000, I have a macro / form field problem which I hope I
explain clearly...

I have a macro that someone kindly gave me which is intended to add rows to
a table within a form.  Upon exiting the last field in the last column of a
row, a new row in meant to be added which copies the form fields from the
current row into the new row, with all of their attributes.  

Within the first row of form fields, there are three columns, each of which
contains a unique form field.  The first is a generic text field, the second
is a drop-down list and the third is another generic text field.  The macro
creates a new row with generic text fields; it does not copy / continue the
drop-down field in the second column.  I need it to do this.  The macro is
listed at the end of this post.

I am not very knowledgeable about macros so please bare with me; I am not
sure what the macro below is doing but  can it be modified so that each of
the three form fields repeat in subsequent rows?  Any and all help is hugely
appreciated.  Cheers.

Sub addrow()
Dim rownum As Long, i As Long
Dim oRng As Word.Range
Dim oTbl As Table
Set oTbl = Selection.Tables(1)
ActiveDocument.Unprotect
oTbl.Rows.Add
rownum = oTbl.Rows.Count
For i = 1 To oTbl.Columns.Count
   Set oRng = oTbl.Cell(rownum, i).Range
   oRng.Collapse wdCollapseStart
   ActiveDocument.FormFields.Add Range:=oRng, _
   Type:=wdFieldFormTextInput
Next i
oTbl.Cell(oTbl.Rows.Count, oTbl.Columns.Count).Range.FormFields(1).ExitMacro
= "addrow"
oTbl.Cell(oTbl.Rows.Count, 1).Range.FormFields(1).Select
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub

Signature

LPS

Doug Robbins - Word MVP - 26 Sep 2006 18:50 GMT
You will find what you want in this article:

http://groups.google.com/group/microsoft.public.word.vba.userforms/browse_frm/th
read/60d3878c07b6c600/b332949fdc30945c?lnk=st&q=form+add+row+dropdown+group%3Ami
crosoft.public.word.*&rnum=4&hl=en#b332949fdc30945c


Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Working with Word 2000, I have a macro / form field problem which I hope I
> explain clearly...
[quoted text clipped - 43 lines]
> ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
> End Sub
LPS - 26 Sep 2006 20:00 GMT
Thank you Doug.  I will give it a try and hope for the best.

Cheers,
Signature

LPS

> You will find what you want in this article:
>
[quoted text clipped - 47 lines]
> > ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
> > End Sub
LPS - 26 Sep 2006 20:23 GMT
Hi again Doug.  I tried the macro at the site you indicated and it is giving
me some kind of error, as follows,
with the first line "Sub NewRow()" highlighted in yellow and the last row
(listed below) just highlighted.

Sub Newrow()
'
' NewRow Macro
' Macro created 2006-Sep-26 by Linda Sgabellone

   ActiveDocument.Unprotect
   Selection.InsertRowsBelow 1
   Selection.HomeKey Unit:=wdLine
   Selection.FormFields.Add Range:=Selection.Range,

Can anyone explain what is going on?

Many thanks,
Signature

LPS

> You will find what you want in this article:
>
[quoted text clipped - 47 lines]
> > ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
> > End Sub
Jay Freedman - 26 Sep 2006 20:39 GMT
Because newsgroup posts are limited in line width, the macro you copied has
line breaks in the middle of statements that must be on one line in order to
work. The line you quoted is only the first of many. You have to delete the
line break that occurs after the comma at the end of that line, combining it
with the next line that starts with "Type".

Everywhere in the code that you see a line with red highlighting, you must
combine two lines. They'll usually be one line that's indented followed by a
second line that starts at the left margin.

In the future, if you want help with an error, it's best to quote *exactly*
the text of any error message -- "some kind of error" just doesn't cut it.

Signature

Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

> Hi again Doug.  I tried the macro at the site you indicated and it is
> giving me some kind of error, as follows,
[quoted text clipped - 77 lines]
>>> --
>>> LPS
LPS - 27 Sep 2006 19:49 GMT
Thank you for your suggestions Jay.   I will try them.  You are absolutely
correct about
providing exact error messages.  I apologise if my post implied there was a
message;
there actually wasn't anything other than highlighted lines of code.  Sorry
about that.

Cheers,
Signature

LPS

> Because newsgroup posts are limited in line width, the macro you copied has
> line breaks in the middle of statements that must be on one line in order to
[quoted text clipped - 90 lines]
> >>> --
> >>> LPS
 
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.