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

Form Fields into a Header

Status
Not open for further replies.

cp33c

Programmer
Sep 19, 2003
13
GB
Hi,
Now this is probably an easy one, but its been driving me crazy for last few hours.

I've got a letter template that graps the address, date, dear X, etc from a lotus notes database and inputs the data into form fields at the beginning of the template. I have a To:, From: and Subject field in a header on the 2nd page. The idea is, is that the header populates from the fields at the beginning of the letter. It works fine if I update the header fields or if I click on print preview, but I want it to work automatically when the template opens. I've tried opening print preview and closing print preview when the document opens, but that does nothing, because the fields at the beginning of the letter only populate after the template is opened. I've also tried the same with updating the fields.

Help!!!
 
Could you post the code that DOES do the population? Or are you saying that you do not have any yet? You state it "works fine", but is what you are doing that "works fine" code? If so, please post.

Gerry
 
Gerry,
Theres no code. I've just added reference fields in the Header that point to the text form fields at the beginning of the letter. When I right-click on one of the reference fields and click update field it puts whatever is in the form field into the reference field. I found somewhere else that when the template is viewed in a print preview it updates the field as well.

I did try some code as the template opened:

Private Sub Document_Open()

ActiveDocument.PrintPreview
ActiveDocument.ClosePrintPreview

End Sub

The only reason I can see that this doesn't work is because the form fields populate after the template has been opened, so it populates after this code has been run. I keep thinking something like a loop that checks the length of the form field until the length is greater than 0 then update the reference fields, end loop. Problem is I don't know what to write (its like writers block but for VBA. I will call it VBA block!!)
 
OK, let me see if I understand. You mentioned form fields in the header, but they are not form fields. They are reference fields, that refer to form fields ELSEWHERE - that is, the form fields are text form fields at the beginning of the document.

Form fields are, generally, used for data input. The user enters something into them (if they are text, or checks them if they are checkboxes).

Could you please describe what is exactly happening? Is there user input into text form fields at the beginning of the document?
reference fields in the Header that point to the text form fields at the beginning of the letter

in which case, why are up trying to update on document open - the user has not input anything into the text form fields yet.

There is something missing in your description of what is happening. Please walk me through step by step what IS happening, and what you WANT to happen. In particular please describe what you did to make the "reference" fields in the header.

It seems to me that what you seem to want is very possible, well, I know it can - unless I am really confused.

But what exactly are the fields in the header? What did you do to make them? Why are you trying to update on document open if the user does not have a chance to inout into the text form fields at the beginning of the document?

Gerry
 
Gerry,

I've managed to sort it out myself. Thanks for your help

Carl
 
I've managed to sort it out myself
Thanks for sharing. Can you please explain the members how you solved your issue ?
 
Yeah sure.

What I wanted to do is to have a reference field in a header of a word template automatically update after 2 seconds from the document opening.

I entered this into the Document_Open event:

Private Sub Document_Open()

Application.OnTime When:=Now + TimeValue("00:00:02"), _
Name:="Timer1"

End Sub

Then created a procedure called Timer1:

Public Sub Timer1()

ActiveDocument.PrintPreview
ActiveDocument.ClosePrintPreview

End Sub

The reason why I used the print preview function was because it does the same thing as right-clicking on the reference field and clicking on Update Field. I couldn't get the update field to work properly, so I used print preview.

I hope this makes sense.
Carl



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top