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 / August 2005

Tip: Looking for answers? Try searching our database.

advise on repeative code item

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nick Calladine - 19 Aug 2005 11:42 GMT
Hi

I currently have a table in which i am populated each added row with a
dropdown box.
I have tried to record the following through the macro record and need two
point answering.

One is there a better coding way of doing this correctly.

Secondly i cant seem to get away of adding to each row cause of syntax of
selecting the last drop down thats it has added
I understand this take the index of the formfield
So i need to work it to so it either finds the maximum index of the
formfield and then minus 1 to get the last added formfield or a better in my
case a general piece which at time of adding select the formfield i just
added.

The formfield is exactly the same in every row.

Please can some one point me in the right direction and shed some light

Many thanks

Code Below -->

   .FormFields.Add Range:=Selection.Range, Type:=wdFieldFormDropDown
    Selection.PreviousField.Select
    With Selection.FormFields(1)
       .Name = "CIS"
       .Enabled = True
       .OwnHelp = False
       .HelpText = ""
       .OwnStatus = False
       .StatusText = ""
   End With

   Selection.FormFields("CIS").DropDown.ListEntries.Clear
   Selection.FormFields("CIS").DropDown.ListEntries.Add Name:="CIS 4"
   Selection.FormFields("CIS").DropDown.ListEntries.Add Name:="CIS 6"
   Selection.FormFields("CIS").DropDown.ListEntries.Add Name:="VAT"
   Selection.FormFields("CIS").DropDown.ListEntries.Add Name:="None"
Greg - 19 Aug 2005 14:20 GMT
If I understand correctly, you are looking for code to add a row to the
end of the selected table and then put a populated dropdown field in
that new row.  Something like this may help:

Sub Test()
Dim i As Long
Dim oRng As Range
Dim fFld As FormField

Selection.Tables(1).Rows.Add
i = Selection.Tables(1).Rows.Count
Set oRng = Selection.Tables(1).Cell(i, 1).Range
Set fFld = oRng.FormFields.Add(Range:=oRng, Type:=wdFieldFormDropDown)
With fFld
 .Name = "CIS" & i
 .Enabled = True
 .OwnHelp = False
 .HelpText = ""
 .OwnStatus = False
 .StatusText = ""
 With .DropDown.ListEntries
   .Add Name:="CIS 4"
   .Add Name:="CIS 6"
   .Add Name:="VAT"
   .Add Name:="None"
 End With
End With
End Sub
 
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.