Customising field codes

G

gwh

Version: 2004
Operating System: Mac OS X 10.4 (Tiger)
Processor: intel

Hi everyone,

I'm trying to automate a proposal document by using field codes. I'm basically using the Fillin field, eg. {FILLIN "ENTER THE NAME OF THE PROPOSAL" \* MERGEFORMAT} to prompt the user for information. If this information is used elsewhere in the document, I've inserted {REF Name_of_Proposal } at each particular point. I also bookmarked the name of the fields that would be populating the other fields as described above, in order to get it working.

The problem is that there's a page in the document where there's a table with two columns - milestone and date. As part of the automation process, I need to create a fillin box for both the milestone and date cells. This is no problem as it'd just work like all the other fillins and the information would populate the cell under "milestone" and the cell under "date". The thing is that there may be more than one row in the table, ie. a necessity to create more than one milestone and date pair. I thought about creating separate fillins labelled milestone1, date1, then milestone2, date2, but I don't know in advance how many of these rows there will be - in fact it will vary for each proposal. So I wondered if someone could tell me if there's any field codes I could use to allow the user to enter all the information needed in the one fillin box but have the ability to somehow separate the different milestone/date pairs that would then get populated consecutively into different table rows. Is this asking too much of field codes or can they be customised to cater for situations like this?

My other issue is that I'd like a message box to pop-up before a particular fillin dialogue appears. This is because there's a section in the proposal where helpful instructions need to be given to the user before filling in the dialogue. Is there a way to incorporate such a pop-up and customise it so that it appears in the correct place?

Really appreciate any help offered.
 
S

Shawn Larson [MSFT]

Unfortunately you are correct, the task you have described is beyond the
capability of fields. With the FILLIN field, there would need to be an
individual field for each milestone and date. Since you have conditional
scenarios ­ sometimes you need an extra table row, sometimes you don¹t ­ you
would need some sort of macro to allow for those conditions. Since you are
working with Mac Word 2004, this could be done in either VBA or AppleScript.

Also, have you considered using an ASK field as opposed to a FILLIN field?
An ASK field behaves much the same way as the FILLIN, dialog box displays
but automatically assigns the value to a specified bookmark. This
eliminates the need for you to manually apply a bookmark to the FILLIN
field.

HTH,
Shawn Larson
Mac Word Test
Microsoft MacBU
 
G

gwh

Thanks for the reply,

I think I'd need to use VBA instead of Applescript since the document will end up being used on a pc and not a mac. Do you know of any online sources where I can get this VBA script to get it to work? And would I need VBA to accomplish the message box effect I was describing?

I've also just tried using ASK instead of FILLIN. I found that when the dialogue box came up (similar to FILLIN), when I entered some information then pressed ok, the bookmark was assigned but the value wasn't entered into the field. From what you were describing I assumed it was identical to FILLIN except it had the added bonus of creating the bookmark automatically. Do you know why this happened?
 
S

Shawn Larson [MSFT]

I don¹t have a list on online VBA resources for you. Our fine MVP
representatives can provide that for you. If they don¹t response to this
post, post a new message to this newsgroup specifically asking for available
online resources. You will need to use VBA to have the message box display.


I¹m not entirely sure why the ASK field bookmark was not entered into the
field. Unless the REF field needs to be updated after clicking OK on the ASK
field.

Shawn Larson
Mac Word Test
Microsoft MacBU
 
J

John McGhie

Thanks Shawn:

THAT will cost you, next month :)

OK, we are rapidly approaching the time when the VBA development becomes a
bit intensive, and you begin to ask yourself whether the project justifies
the time spent.

You can being with www.word.mvps.org/FAQs/MacrosVBA/index.htm

Lots of good stuff on VBA there, and a lot of it is old enough that it will
work unchanged in Word 2004.

Before you start, you have to decide what you are going to do about two
problems:

1) To have VBA work for other users, you either have to put the VBA in a
template that is accessible to all users, or you have to put it in the
document itself. If you put it in the document, most AntiVirus will not
permit the document to be opened by other users or emailed anywhere. You
can overcome that on the PC by code-signing, but if you do, Word Mac won't
run it.

2) Your requirement to have a dialog box spring up needs you to hook the
OnEntry event of a field. Unless you want to do a hell of a lot of coding,
that really means you should create a UserForm.

3) Setting up a table populated with multiple repeating rows is another job
for a UserForm, where you can create a control bound to a ComboBox. I think
I would try very hard to delete this from your requirement. It will be much
easier for you and the users if they can just type their milestones and
dates into a Word table in the document.

4) If you do use a UserForm, you can write code to populate a Document
Property. You can insert custom document properties as fields throughout
the document. This is a more robust way of doing it: the UserForm and its
document properties are less likely to get damaged by inexperienced users
typing over the top of them.

5) Word 2004 is not a good place to be attempting this. It does not have
the generous Visual Basic Editor that Word 2003 has. You will save a lot of
time if you use the Word 2003 VBE to develop this.

The other reason I suggest working in Word 2003 is that its help is a lot
better for this kind of thing than Word 2004's. However, you can access the
Word 2003 VBA Help online, and you can also download it as a compiled PC
Windows Help file.

I think we should concentrate on getting those ASK fields working first.
That's 90 per cent of your requirement, and offers the best bang for your
buck.

As Shawn said, an ASK field populates the bookmark that you nominate with
the user's entry. You then need to add at least one REF field AFTER the ASK
field, and update it after the user has made their entries. You can, of
course, have several REF fields pointing at the same bookmark. Don't forget
that bookmark names must not contain spaces.

It's not a good idea to use a FILLIN field here, the FILLIN field simply
inserts the user's text in the document, it doesn't bookmark it.

Hope this helps

I don¹t have a list on online VBA resources for you. Our fine MVP
representatives can provide that for you. If they don¹t response to this
post, post a new message to this newsgroup specifically asking for available
online resources. You will need to use VBA to have the message box display.


I¹m not entirely sure why the ASK field bookmark was not entered into the
field. Unless the REF field needs to be updated after clicking OK on the ASK
field.

Shawn Larson
Mac Word Test
Microsoft MacBU

--
Don't wait for your answer, click here: http://www.word.mvps.org/

Please reply in the group. Please do NOT email me unless I ask you to.

John McGhie, Consultant Technical Writer
McGhie Information Engineering Pty Ltd
http://jgmcghie.fastmail.com.au/
Sydney, Australia. S33°53'34.20 E151°14'54.50
+61 4 1209 1410, mailto:[email protected]
 
G

gwh

Thanks for the reply John,

I planned to create a template so that it would be accessible to all users.

I've started some coding on my userform in order to get it to work (current code at end of this post).

I have two coding problems at the moment that I'm hoping someone can help me with.

I've been trying to set up a wizard interface on the userform. I have the code (listed below) but it was originally written for a multi-page userform with 3 pages only, whereas I have about 11 pages. I was able to adapt the code a little bit by disabling all pages except for the first page but when it comes to coding the procedures for the "back" and "next" buttons I'm getting a bit lost. As I have so many pages, I thought that if I used the current code I'd end up with bloated code. Instead, I was thinking about declaring a variable called "current page" and having this somehow keep track of the current page in order to get it to work.
Problem is I don't know how to adapt the code to do this, and wondered if I could get some coding tips with this particular issue?

My second challenge is regarding my original problem, ie. populating a table from values entered into the userform (as discussed originally). They want all the information to be entered from the one userform dialogue box so I don't think I could put your suggestion to them about getting them to fill in the table from the document itself. I'm trying hard to understand your coding suggestions to get the table to work. You were saying to create a control bound to a ComboBox - can you expand on this, I mean they need to type in a number of milestone and date pairs, so how would this work with a combobox? You were then saying that I can "write code to populate a Document Property" and "insert custom document properties as fields throughout the document". I'm not sure how this would work either - do you have some sample code I could study so I could adapt it to my circumstance?

Also regarding the use of ASK fields - I'm not sure if this would be relevant since I'm using a userform now?

Would really appreciate any continued support.

Option Explicit

Private Sub UserForm_Initialize()

With MultiPage1
' The next 10 lines disable all pages except Page1.
..Pages(1).Enabled = False
..Pages(2).Enabled = False
..Pages(3).Enabled = False
..Pages(4).Enabled = False
..Pages(5).Enabled = False
..Pages(6).Enabled = False
..Pages(7).Enabled = False
..Pages(8).Enabled = False
..Pages(9).Enabled = False
..Pages(10).Enabled = False
' Make Page1 the active page.
..Value = 0
End With

' Set the caption on the CommandButtons.
cmdBack.Caption = "Back"
cmdBack.Enabled = False
cmdForward.Caption = "Next"

End Sub

' Procedure for the "Back" button
Private Sub cmdBack_Click()

' Declare variables

Dim currentPage As String
currentPage = "Pages(0)"

Select Case MultiPage1.Value
Case 1 ' If Page2 is active...
With MultiPage1
..Pages(0).Enabled = True ' Enable Page1.
..Value = MultiPage1.Value - 1 ' Move back 1 page.
..Pages(1).Enabled = False ' Disable Page2.
End With

cmdBack.Enabled = False ' Disable Back button.

Case 2 ' If Page3 is active...
With MultiPage1
..Pages(1).Enabled = True ' Enable Page2.
..Value = MultiPage1.Value - 1 ' Move back 1 page.
..Pages(2).Enabled = False ' Disable Page3.
cmdForward.Caption = "Next"
End With
End Select

End Sub

' Procedure for the "Next" button
Private Sub cmdForward_Click()

Select Case MultiPage1.Value
Case 0 ' If Page1 is active...
With MultiPage1
..Value = MultiPage1.Va
 
J

John McGhie

Well, it's time to turn this over to the experts!

Your code contains a selection of "I wouldn't do it that way" instances :)
However, I am not a user form person (I try to avoid them!).

So let's see what the experts down the hall have to say... They need to
know that you're coding this on a Mac, so you are stuck back in VBA 5. They
will also need to know what version of PC Word you intend to run on. For
now, let's assume Word 2003.

(Cross-posting to m.p.w.vba.userforms).

To stay up with this discussion, you need to configure Entourage to pick
newsgroup microsoft.public.word.vba.userforms up, as described here:

http://word.mvps.org/Mac/AccessNewsgroups.html

The Mactopia forum can't handle cross-posted posts!

When you get over there, you will find that it massively enhances your
chances of getting a useful reply if you add your NAME to your posts. The
folks over there are industry veterans with 20+ years of commercial coding
experience, and they appreciate the ability to talk with "real" people.
This is NOT a "blog" :)

Cheers


Thanks for the reply John,

I planned to create a template so that it would be accessible to all users.

I've started some coding on my userform in order to get it to work (current
code at end of this post).

I have two coding problems at the moment that I'm hoping someone can help me
with.

I've been trying to set up a wizard interface on the userform. I have the code
(listed below) but it was originally written for a multi-page userform with 3
pages only, whereas I have about 11 pages. I was able to adapt the code a
little bit by disabling all pages except for the first page but when it comes
to coding the procedures for the "back" and "next" buttons I'm getting a bit
lost. As I have so many pages, I thought that if I used the current code I'd
end up with bloated code. Instead, I was thinking about declaring a variable
called "current page" and having this somehow keep track of the current page
in order to get it to work.
Problem is I don't know how to adapt the code to do this, and wondered if I
could get some coding tips with this particular issue?

My second challenge is regarding my original problem, ie. populating a table
from values entered into the userform (as discussed originally). They want all
the information to be entered from the one userform dialogue box so I don't
think I could put your suggestion to them about getting them to fill in the
table from the document itself. I'm trying hard to understand your coding
suggestions to get the table to work. You were saying to create a control
bound to a ComboBox - can you expand on this, I mean they need to type in a
number of milestone and date pairs, so how would this work with a combobox?
You were then saying that I can "write code to populate a Document Property"
and "insert custom document properties as fields throughout the document". I'm
not sure how this would work either - do you have some sample code I could
study so I could adapt it to my circumstance?

Also regarding the use of ASK fields - I'm not sure if this would be relevant
since I'm using a userform now?

Would really appreciate any continued support.

Option Explicit

Private Sub UserForm_Initialize()

With MultiPage1
' The next 10 lines disable all pages except Page1.
.Pages(1).Enabled = False

.Pages(2).Enabled = False

.Pages(3).Enabled = False

.Pages(4).Enabled = False

.Pages(5).Enabled = False

.Pages(6).Enabled = False

.Pages(7).Enabled = False

.Pages(8).Enabled = False

.Pages(9).Enabled = False

.Pages(10).Enabled = False

' Make Page1 the active page.
.Value = 0

End With

' Set the caption on the CommandButtons.
cmdBack.Caption = "Back"
cmdBack.Enabled = False
cmdForward.Caption = "Next"

End Sub

' Procedure for the "Back" button
Private Sub cmdBack_Click()

' Declare variables

Dim currentPage As String
currentPage = "Pages(0)"

Select Case MultiPage1.Value
Case 1 ' If Page2 is active...
With MultiPage1
.Pages(0).Enabled = True ' Enable Page1.

.Value = MultiPage1.Value - 1 ' Move back 1 page.

.Pages(1).Enabled = False ' Disable Page2.

End With

cmdBack.Enabled = False ' Disable Back button.

Case 2 ' If Page3 is active...
With MultiPage1
.Pages(1).Enabled = True ' Enable Page2.

.Value = MultiPage1.Value - 1 ' Move back 1 page.

.Pages(2).Enabled = False ' Disable Page3.

cmdForward.Caption = "Next"
End With
End Select

End Sub

' Procedure for the "Next" button
Private Sub cmdForward_Click()

Select Case MultiPage1.Value
Case 0 ' If Page1 is active...
With MultiPage1
.Value = MultiPage1.Va
Version: 2004
Operating System: Mac OS X 10.4 (Tiger)
Processor: intel

Hi everyone,

I'm trying to automate a proposal document by using field codes. I'm basically
using the Fillin field, eg. {FILLIN "ENTER THE NAME OF THE PROPOSAL" \*
MERGEFORMAT} to prompt the user for information. If this information is used
elsewhere in the document, I've inserted {REF Name_of_Proposal } at each
particular point. I also bookmarked the name of the fields that would be
populating the other fields as described above, in order to get it working.

The problem is that there's a page in the document where there's a table with
two columns - milestone and date. As part of the automation process, I need to
create a fillin box for both the milestone and date cells. This is no problem
as it'd just work like all the other fillins and the information would
populate the cell under "milestone" and the cell under "date". The thing is
that there may be more than one row in the table, ie. a necessity to create
more than one milestone and date pair. I thought about creating separate
fillins labelled milestone1, date1, then milestone2, date2, but I don't know
in advance how many of these rows there will be - in fact it will vary for
each proposal. So I wondered if someone could tell me if there's any field
codes I could use to allow the user to enter all the information needed in the
one fillin box but have the ability to somehow separate the different
milestone/date pairs that would then get populated consecutively into
different table rows. Is this asking too much of field codes or can they be
customised to cater for situations like this?

My other issue is that I'd like a message box to pop-up before a particular
fillin dialogue appears. This is because there's a section in the proposal
where helpful instructions need to be given to the user before filling in the
dialogue. Is there a way to incorporate such a pop-up and customise it so that
it appears in the correct place?

Really appreciate any help offered.


--
Don't wait for your answer, click here: http://www.word.mvps.org/

Please reply in the group. Please do NOT email me unless I ask you to.

John McGhie, Consultant Technical Writer
McGhie Information Engineering Pty Ltd
http://jgmcghie.fastmail.com.au/
Sydney, Australia. S33°53'34.20 E151°14'54.50
+61 4 1209 1410, mailto:[email protected]
 
O

Officelink

Thanks again for the reply John,

I've subscribed to this vba newsgroup as you suggested through entourage.
I've never actually used newsgroups like this before, ie. via a reader so
I'm not exactly sure how it works. I assume that if anyone's interested in
giving me a hand they can read this history?

I found out today what version of Word they'll be using. Apparently some
have the 2003 version but most of them have 2000 or XP versions. That's what
I was told anyway.

So here's hoping I get some replies.

Thanks again,

Gabrielle
 
D

Doug Robbins - Word MVP

I would suggest that you tell us in plain English what it is that you want
to do, rather than how you have tried to go about it.

All that business about Pages and the select case doesn't appear to make
much sense.

I gather that you have give up on the fill-in fields approach in favour of a
user form (with which I concur)

As for the table of milestones, If you want that to be done via the
userform - probably not necessary unless you already have them in some other
source - as the user could just enter the milestones directly in the
document. If they are already available from some other source, they could
be loaded into an array from that source and then displayed in a listbox on
the userform if desired, or just be entered directly into the document by
iterating through the array.

--
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
 
O

Officelink

Thanks for the reply Doug,

Okay so I'll start from the beginning if that's alright. The people who I'm
designing the form for have a number of documents - proposals, reports etc.
that they have to fill in regularly. The problem at the moment is that when
some of the users complete the documents, they're either not following the
formatting styles set up and/or they accidentally move page elements around
etc. I proposed setting up a userform so that once the document opens,
they'll have all the fields necessary to complete the file right there in
the dialogue box so that when they finish entering everything, all the
information will automatically populate the file, taking on all the styles
and all they'll have to do is print it, leaving very little room for error.

I worked out that I'd need about 11 different pages in the userform which
would correspond to the different pages in the document that need to be
populated with information. I've set up bookmarks in the document, marking
each of the points in the file where information will go. There are certain
points in the file where a REF field would be needed so that where certain
values are repeated, these would automatically get slotted into the right
area.

So I've set up a multi-page userform but have only gotten so far. I want to
make it into a wizard like interface so that the user goes from page to page
via next and back buttons, then when they finally get to the end page and
have filled the whole form out, after pressing finish, the information would
jump into the correct fields throughout the file. Most of the controls in
the userform would probably just need to be input textboxes because the
information is short, although some would have to be multiline where a few
paragraphs are called for.

Regarding the table of milestones, I'm not sure how this would work because
unlike all the other information that would be getting entered into a basic
textbox then populating a specific field in the file, the milestones require
the user to enter a milestone and a date. This milestone and date needs to
then be entered into a table, with the milestone being in one column and the
date in the other column. The problem is that there will always be more than
one milestone date pair being entered by the user and it will be different
for each user. This would mean I don't know in advance how many rows in the
table there will need to be to accommodate the amount of milestone/date
pairs.

The other requirement is that once the finish button is pressed and all the
document is populated, is there a way for the cursor to jump to a specific
spot in the document, to remind the user to input a job number that they
need to acquire at a later stage. This last step is necessary because they
won't have this number prior to filling out the form.

And just as a final thought: I know that the use of labels within the
userform is to instruct the user on what each particular control is used
for. On one of the input textboxes I wanted to provide about a paragraph of
information that would help the user to fill in that particular textbox
better, and I was just going to use a larger label to do this. I'm not sure
though that this is the correct use for a label in this type of situation,
and wondered whether it would be more appropriate to have a message box pop
up with this extra information once the user has focussed on the particular
input box. Can you also comment on this?

So I don't know if what I've described is hard to set up, but if you could
help me with getting this together, I'd really appreciate it.

Thanks again,

Gabrielle
 
D

Doug Robbins - Word MVP

I would not bother disabling all of the pages. In the Initialize event of
the form set the .Value of the multipage to 0 so that the first page is the
active one when the form loads.

Then to allow the user to move through the form, put a coupe of command
buttons outside the mutlipage, one named cmdNext and the other cmdPrevious
and have the following code associated with them

Private Sub cmdNext_Click()
Dim i As Long
i = MultiPage1.Value
If i < 10 Then
MultiPage1.Value = i + 1
Else
MultiPage1.Value = 0
End If
End Sub

Private Sub cmdPrevious_Click()
Dim i As Long
i = MultiPage1.Value
If i > 0 Then
MultiPage1.Value = i - 1
Else
MultiPage1.Value = 10
End If
End Sub

For the milestones, on the page of the multipage where you want them to be
dealt with, insert a list box and a series of textboxes, one for each
component of the milestone item (the number, maybe a description and the
date pairs). The listbox will need to have the same number of columns as
there are of the abovementioned text boxes. Then you also need a couple of
command buttons, one to add the milestone from the text boxes to the
Listbox, another to delete the selected item in the Listbox and a third to
Edit the selected item in the ListBox. The last button would set the values
of the textboxes to the values of the selected items (using the .BoundColumn
property of the ListBox) and then deletes the items from list so that when
the Add button is used, the item is not duplicated.

When you go to transfer the information from the list box to the document,
you would iterate through the items in the Listbox and add a row to a table
for each item as you come to it and populate the cells in that row with the
components of the milestones. You will probably want to incorporate a
routine in the command button event that causes this to happen to sort the
rows of the table so that the items are in order.

--
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