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

Prompting a user for input into a field in a Word Doc

Status
Not open for further replies.

icodian

IS-IT--Management
Aug 28, 2001
74
US
Hi,

I've created a template in Word 2003. I have a Header that I would like to display a title in. However, rather than having the user have to open up the header and change the title, I would like to simply prompt the user to enter one whenever they create a new doc off of the template.

I found thread68-830116 that supplied a link to one way to do this. It had me set bookmarks, then enter the code below in VBA.

When creating a new doc from the template, the prompt appears and allows me to enter a title. However, upon pressing OK, the prompt disappears and I am left with a blank doc. My header does not exist on this doc for some reason and therefore the title does not appear.

As a note, the bmkTitle bookmark is located in the header and the bmkStartHere bookmark is located on the first line of the document.

Any ideas on why after I enter the title in my little form and press OK, the blank document that appears does not include my header?

Thanks for any assistance!

Private Sub Document_New()
Dim oForm As frmTitle

On Error GoTo Error_DocumentNew

Set oForm = New frmTitle

oForm.Tag = "Cancel"
oForm.Show

If oForm.Tag = "OK" Then
'ActiveDocument.Bookmarks("bmkTitle").Range.Text = oForm.txtTitle.Text
'ActiveDocument.Bookmarks("bmkStartHere").Range.Select

Unload oForm
Set oForm = Nothing
Else
Unload oForm
Set oForm = Nothing
ActiveDocument.Close wdDoNotSaveChanges
End If

Exit_DocumentNew:

Exit Sub

Error_DocumentNew:
On Error Resume Next

Unload oForm
Set oForm = Nothing
ActiveDocument.Close wdDoNotSaveChanges

Resume Exit_DocumentNew
End Sub
 
You know what? Nevermind. I'm an idiot. Turns out that everything was working fine. The header was simply not being displayed as I was used to seeing it. I had to go view the header and then close it in order to see it show (greyed out) on the document.

To follow up on this then. Is there an option or a line of code that will make the header with the title in it visible immediately without having to go to View->Header and Footer?

Thanks again!
 
Not sure why you are making the form like that. In any case, if I have a form (frmTitle) IN the template and call it with Document_New:
Code:
Private Sub Document_New()
frmTitle.Show
End Sub
and on the form I have a textbox (txtTitle), and a Commandbutton, clicking the commandbutton definitely inserts the text into the bookmark in the header.
Code:
Private Sub CommandButton1_Click()
ActiveDocument.Bookmarks("bm_Header").Range.Text = txtTitle.Text
Unload Me
End Sub
Look up Tag in Help. Tag stores information about an object, it not used to carry out instructions.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top