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

Page break macro in a form

Status
Not open for further replies.

Delano29

Technical User
Jul 10, 2001
28
US
Hi,

I am using a form in MS Word. I created a macro to insert a choice of documents in one of the form fields. When the document is inserted it breaks the form in an area that is not desirable. Is there a way of inserting a page break in a specified area on the form using a macro? For instance, maybe in a bookmark, form field, row in a table, etc. This way I have some control. In addition, I would need code to delete the page break as well if the users choice of insert document changes. I have tried the ‘keep together’ function without success.

Thanks.
 
All the things you mention are possible. However, this becomes a VBA question, or questions. Please post to the VBA forum.

I do have to question the funtionality though. You say "documents". You are inserting whole files, as files? Is this required? Could you change that to inserting text, as required?

Further, you would need to spell out the logic required precisely. WHY would the user be changing the document inserted? Could be changing part of it? Or is it either/or; document in/document out.

Is this from a template? Are you generating a new document, with whatever elements the user decides to include? WHAT would cause them to remove an inserrted document?

faq219-2884

Gerry
My paintings and sculpture
 
Thanks.

I'll try reposting it to the VBA section. The form is a word template that generates a new form. The text of the documents (located in another directory) are inserted rather than the entire document. When the user selects a command button a form comes up giving a choice of inserting just one document out of five being offered in the form field depending on what assignment they are working on. I gave them the option of changing or deleting the inserted text just in case they selected the wrong information.

This is part of the code I use to insert the documents text into the form field:

ActiveDocument.FormFields("text44").TextInput.Clear
Selection.GoTo what:=wdGoToBookmark, Name:="text44"
Selection.Collapse direction:=wdCollapseStart
Selection.MoveRight wdCharacter, 1
Selection.InsertFile FileName:="c:\documents and settings\all users\documents\service1.doc", link:=True
 
This should be moved to the VBA forum, but I would dispute some design elements here.

Formfields are for user input. DIRECT user input. In other words, the user actually enters (types) the content.

In your case, the user makes a decision as to what should be content. YOU, as the developer, are putting the actual content in. In which case, I would say do not use formfields, as they are (as stated) for user input.

"I gave them the option of changing or deleting the inserted text just in case they selected the wrong information."

How? And more importantly...when?

You may want to reconsider some design. For example, you could use bookmarks (real bookmarks), and use INCLUDETEXT.
Code:
With ActiveDocument.Bookmarks("BM1").Range
   .Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
   Text:= _
      "INCLUDETEXT  ""c:\\documents and settings\\all users\\documents\\service1.doc"" ", PreserveFormatting:=True
End With

faq219-2884

Gerry
[url=http://www3.telus.net/public/fumei/]My paintings and sculpture[/url]
 
Actually, you can insert a page break with field coding, so a macro-based solution might not be needed. Other than that, I fully agree with Gerry's observations.

Cheers

[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top