Userforms and bookmarks

B

Beth Brooks

Hi!

For my template, I've created an autonew macro that displays a userform
prompting the user for a title, code, and date. The responses are displayed
in the file via bookmarks.

I've also created an autoopen macro that prompts the user for a new date.
The problem is that the new date gets added to the bookmark in front of the
existing date (entered when the file was created. I end up with this:

10 Feb 200609 Feb 2006

Any suggestions on how to fix this would be welcome!

Thanks!

Beth
 
D

Doug Robbins - Word MVP

Instead of using bookmarks, insert { DOCVARIABLE varname } fields in the
document and in the code in the user form, use

With ActiveDocument
.Variables("varname").Value = txtcontrolname
etc.
.Range.Fields.Update
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
B

Beth Brooks

Doug,

Thank you! That worked very well. I have a couple of follow-up questions:

The variables are used in a template. When a user creates a new document
based on this template, a userform prompts them for the title, code, and
date. However, when I open the template, I don't get that prompt, so the
variables have no initial value. I tried setting a value for each of the
fields, but I must have done it in the wrong place, because it didn't work.
How (more importantly where) do I set an initial value for each variable?
(BTW, for the short term, I've created a new file based on the template, set
the variable values using the userform, and then saved the resulting document
as a template. But I'd like to know how to fix this issue for the long term.)

Second, I'd like to give the users of this template a way to modify the
values of these three variables at will, in case they typed something
incorrectly or the information changes. I'd like to put a button on a toolbar
that brings up the userform displayed when a new file is created. Is that
possible and, if so, how do I do it?

I very much appreciate your help! I'm an editor trying to fill the role of a
developer and I'm in way over my head!

Thanks!

Beth
 
D

Doug Robbins - Word MVP

A value can only be assigned to a variable using code. Normally, the user
should not be opening the template. You can put a button on the toolbar
that runs the autonew macro. You can use code such as the following to
populate the controls on the form with the data from the variables when the
user reloads it when they are working in document:

Private Sub UserForm_Initialize()
With ActiveDocument
txtCompany = .Variables("Company").Value
txtProject = .Variables("Project").Value
txtDocNum = .Variables("DocNum").Value
txtRevNum = .Variables("Revision").Value
txtDocTitle = .Variables("DocTitle").Value
End With
End Sub



--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top