PDA

View Full Version : Setting multiple Values in a form field?



spinnaker
09-28-2005, 09:35 AM
I have a template which contains various form fields. I am using COM to set the value of these fields:

wd.FormFields("LOFAmount").Result = doc.LOFAmount(0)

(The "doc" stuff is actually Lotus Script).


I need to have multiple values for one field in particular. One thought was to place mutiple form fields on the template for these values but my number of values is unknow. I guess I could hide the ones hat are not being used. Is there an easier way to accomplish this?

fumei
09-28-2005, 09:04 PM
Please give more explanation, and perhaps more code.

A field contains one value. It is assigned. Are you asking for a source of values that coluld possibly be used, depending on some logic?

if so, use an array. please post what the logic is.

spinnaker
09-29-2005, 04:27 AM
Please give more explanation, and perhaps more code.

A field contains one value. It is assigned. Are you asking for a source of values that coluld possibly be used, depending on some logic?

if so, use an array. please post what the logic is.

Thanks, how do I insert an array of fields in Word? Even with an array, I still have the problem of hiding the unused fields. Because the fields are in a columar format:

Field1
Field2
Field3
Field4
Field5

If all I use is Field1 then I don't want a blank line for Field2, Field3 etc.

Plus I would need to know ahead of time how many fields that I need.

TonyJollans
09-29-2005, 07:56 AM
Hi spinnaker,

Welcome to VBAX!

Help me out here; I'm confused!

FormFields are for people to fill in.

Programs don't need them. Why can't you just write however much text you've got exactly where you want it in your document?

spinnaker
09-29-2005, 08:30 AM
Hi spinnaker,

Welcome to VBAX!

Help me out here; I'm confused!

FormFields are for people to fill in.

Programs don't need them. Why can't you just write however much text you've got exactly where you want it in your document?

How I am I supposed to know where to write the values? My users are responsible for creating the template. They place a field where ever they want the value to appear. I simply fill the field in so the value appears where they want. If you know of a better way then please let me know.

TonyJollans
09-29-2005, 09:33 AM
If I understand, whether you use FormFields or not, you have a location in a document where you want to put a list of items.

At that (single) location put the first item, then a return, then the second item, etc. Something like this?

myString = doc.LOFAmount(0)
For i = 1 to numberofitems
myString = myString & vbCR & doc.LOFAmount(i)
Next

wd.FormFields("LOFAmount").Result = mystring

spinnaker
09-29-2005, 10:41 AM
If I understand, whether you use FormFields or not, you have a location in a document where you want to put a list of items.

At that (single) location put the first item, then a return, then the second item, etc. Something like this?

myString = doc.LOFAmount(0)
For i = 1 to numberofitems
myString = myString & vbCR & doc.LOFAmount(i)
Next

wd.FormFields("LOFAmount").Result = mystring


Thanks, I already thought of that but did not think it would work.

There is no vbCR in Lotus Script.

I tried:

temp = temp & Chr(13) & v

and

temp = temp & Chr(13) & Chr(10) & v


I see the values but I get a little square box where the CR or CR/LF should be.


I wonder if I could use a multi-line edit control as apposed to a form field?

MOS MASTER
09-29-2005, 02:36 PM
Hi and welcome to VBAX! :hi:

I'm lost here as well....

The way I read it you want a fill in document which will generate a new line of formfields if you require it and if you don't then it won't add any more right?

There are ways of autogenerating more fields in a fill in form but I need the exact requirements to code for it well.

But then again I don't understand the question to well and could be off. :whistle:

TonyJollans
09-30-2005, 02:58 AM
Hi spinnaker,

I've checked the LotusScript documentation and Chr(13) ought to work (although Chr(10) will likely generate a little box). I'm afraid I really don't understand and am not sure how much more i can help without an environment to test in.

spinnaker
09-30-2005, 06:52 AM
Hi spinnaker,

I've checked the LotusScript documentation and Chr(13) ought to work (although Chr(10) will likely generate a little box). I'm afraid I really don't understand and am not sure how much more i can help without an environment to test in.

I got it to work (kind of). Turns out the problem was the table. The form field is placed in a table. When I run the script the strange character appears. If the field is placed outside the table or if the size of the table is already high enough to accomodate the multiple lines then it works fine.

So it looks like adding to the form field with multiple lines, is not grpwing the cell, it is placing the little box where the CR should be instead. I would really like to place the from field within a table and not know how tall the cell needs to be.

spinnaker
09-30-2005, 07:46 AM
Hi and welcome to VBAX! :hi:

I'm lost here as well....

The way I read it you want a fill in document which will generate a new line of formfields if you require it and if you don't then it won't add any more right?

There are ways of autogenerating more fields in a fill in form but I need the exact requirements to code for it well.

But then again I don't understand the question to well and could be off. :whistle:

I can't understand what the confusion is. I am not the one creating the template. I cannot just add fields when needed because I have no idea where the user might want them. All I am doing is supplying data from a database to a pre existing Word template. The only requirement is that certain form fields exist on the tempate. The end user can place them anywhere on the document just as long as they are there. This is the third time I have exlpained this, I don't know any other way to make it more clear.

TonyJollans
09-30-2005, 09:19 AM
I got it to work (kind of). Turns out the problem was the table. The form field is placed in a table. When I run the script the strange character appears. If the field is placed outside the table or if the size of the table is already high enough to accomodate the multiple lines then it works fine.

So it looks like adding to the form field with multiple lines, is not grpwing the cell, it is placing the little box where the CR should be instead. I would really like to place the from field within a table and not know how tall the cell needs to be.

Sounds like the Table Properties might to be blame for this. The Row Height mustn't be "Exact" if you want the row to be able to expand.

You can check in codeWith ActiveDocument.FormFields("YourFieldName").Range
If .Information(wdWithInTable) Then
If .Rows(1).HeightRule = wdRowHeightExactly Then
.Rows(1).HeightRule = wdRowHeightAtLeast
End If
End If
End Withbut you will need the document unprotected first.

spinnaker
09-30-2005, 09:43 AM
Sounds like the Table Properties might to be blame for this. The Row Height mustn't be "Exact" if you want the row to be able to expand.

You can check in codeWith ActiveDocument.FormFields("YourFieldName").Range
If .Information(wdWithInTable) Then
If .Rows(1).HeightRule = wdRowHeightExactly Then
.Rows(1).HeightRule = wdRowHeightAtLeast
End If
End If
End Withbut you will need the document unprotected first.


Thanks Tony,

You say the "table properties" my be to blame. But it looks like that you are modifying the properties of the form field. Can you please explain?

spinnaker
09-30-2005, 09:58 AM
Sounds like the Table Properties might to be blame for this. The Row Height mustn't be "Exact" if you want the row to be able to expand.

You can check in codeWith ActiveDocument.FormFields("YourFieldName").Range
If .Information(wdWithInTable) Then
If .Rows(1).HeightRule = wdRowHeightExactly Then
.Rows(1).HeightRule = wdRowHeightAtLeast
End If
End If
End Withbut you will need the document unprotected first.

That did not seem to work. Here is the VBScript version that I placed in a macro in the document for testing purposes:


With ActiveDocument.FormFields("TIAmount").Range
If .Information(wdWithInTable) Then
If .Rows(1).HeightRule = wdRowHeightExactly Then
.Rows(1).HeightRule = wdRowHeightAtLeast
End If
End If
End With
ActiveDocument.FormFields("TIAmount").Result = "Line1" & Chr(13) & "Line2"



I debugged it and the the "If .Information(wdWithInTable) Then" line indeed detects that it is in a table but the "If .Rows(1).HeightRule = wdRowHeightExactly Then" line returns false to the next line is not executed.

TonyJollans
09-30-2005, 09:59 AM
If the Range of the FormField intersects a table, then access to the whole table is available via it.

The code works on the first (table) row which intersects the formfield.

spinnaker
09-30-2005, 10:18 AM
It's strange. If I type a CR after the form field within the template then I can have as many lines that I want.

I would rather not have to have my users do this but if it is required then so be it.

I don't suppose there is a way for me to know the first loacation in the document following the form field so that I could use VBA to place the CR?

TonyJollans
09-30-2005, 10:44 AM
Provided, again, the document is unprotected, you can do document_ref.FormFields("field_name").Range.InsertParagraphAfter

spinnaker
09-30-2005, 11:04 AM
Provided, again, the document is unprotected, you can do document_ref.FormFields("field_name").Range.InsertParagraphAfter

You are indeed a wealth of information. Thank you very much.

:bow:

This works just fine:



With ActiveDocument.FormFields("TIAmount").Range
If .Information(wdWithInTable) Then
ActiveDocument.FormFields("TIAmount").Range.InsertParagraphAfter
End If
End With
ActiveDocument.FormFields("TIAmount").Result = "Line 1" & Chr(13) & "Line 2" & Chr(13) & "Line 3" & Chr(13) & "Line 4" & Chr(13) & "Line 5"



The only problem is that it leaves and extra line after the form field but what the heck it works. Thanks again for your help. Now I'll I need to do is to convert this to Lotusscript. :)


Just a few more questions.

I noticed that the Protect Form button is disabled in my toolbar. What would cause this? The document does not seem to be locked.

Any easy way to know that a form field exists in the document other than looping trough the forms collection and looking for the name?

TonyJollans
09-30-2005, 12:04 PM
I noticed that the Protect Form button is disabled in my toolbar. What would cause this? The document does not seem to be locked.

Any easy way to know that a form field exists in the document other than looping trough the forms collection and looking for the name?

I'm afraid there is no easy way to check for the existence of something (something sadly lacking in Word). You can either do as you say and walk the collection, or you can try and reference it and trap the error.

I don't know any reason for the protect form button to be disabled off the top of my head (except if you're editing headers or something)

Good luck with the LotusScript!

MOS MASTER
09-30-2005, 04:03 PM
This is the third time I have exlpained this, I don't know any other way to make it more clear.

Hi :hi:

I'm very sorry you had to repeat youreself. I'm not always capable in reading the English language in the way that for instance Tony can so that's the cause for the confusion. :whistle:

MOS MASTER
09-30-2005, 04:07 PM
Any easy way to know that a form field exists in the document other than looping trough the forms collection and looking for the name?

No Easy way I'm afraid. The bookmark collection does have a Exists property which the formfield collection doesn't have. (You can test a formfield like a bookmark with that property but it isn't foolproof cause it could be a normal bookmark instead)

This kb has a nice Is Formfield Function in it for you to test if a formfield is in there and it has a wealth of knowledge on dealing with bookmarks in Word:
http://vbaexpress.com/kb/getarticle.php?kb_id=562

Good luck! :yes