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

How to keep values in a form!

Status
Not open for further replies.

carrefo

Programmer
Feb 20, 2004
8
BE
Hi everybody.
I have a word documend with formfields, TextInput, DropDown and CheckBox. In one of the pages I allow the users to duplicate that page by inserting a new section in the document and copying everything in the range of the precedent section. Everything goes Ok, all fields are updated with the exception of the DropDown and CheckBox. It's my first work in VBA (I'm PowerBuilder :)) I'm stuck and the work must be ready quick.
I join the code and maybe some one can help me and/or correct this, before I go nuts :)

Private Sub CommandButton1_Click()

ActiveDocument.Unprotect Password:="W8ynfLP" '

fcount = ActiveDocument.Fields.Count
ReDim aFields(fcount)
For Each aField In ActiveDocument.Fields
aFields(aField.Index) = aField.Result
Next aField


ActiveDocument.FormFields("t_endA2").Select
Selection.MoveUp Unit:=wdLine, Count:=1

li_section = ActiveDocument.Sections.Count
Set aDoc = ActiveDocument
Set myRange = aDoc.Range(aDoc.Sections(li_section).Range.Start, End:=Selection.End)
myRange.Copy
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.PasteAndFormat (wdPasteDefault)

ActiveDocument.Protect Password:="W8ynfLP", NoReset:=False, Type:= _
wdAllowOnlyFormFields

For Each aField In ActiveDocument.Fields
aField.Result = aFields(aField.Index)
Next aField

End Sub

Any help is welcome!
Thanks

Francisco Carreta
 
Not totally sure what you are trying to do.

When you are copying the formfields, are you trying to copy the results? It seems that way. You can copy the formfields, but checkboxes use a Value that is boolean, and dropdowns use the Name of the indexed Value. Regarding the drop down, that would only return the selected item - not all of them.

Also I notice this is a sub that is an event for a button. What else is on the form that the button is on? The variables are not declared in this sub, so I assume they are declared somewhere else.

Why are you copying the formfields? If you want to duplicate the new (copied) checkbox you will have to set the Value as either true or false. You will have to set the add the existing items for the drop down to the new one.


Gerry
Painting/Sculpture site:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top