Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2005

Tip: Looking for answers? Try searching our database.

Error whilst fields are updating

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jeanmac - 20 Sep 2005 10:12 GMT
I have designed a report template using ASK fields (the report cannot be
protected and tables are not practical).  A macro placed in the ThisDocument
module prompts the ASK fields and it all works beautifully except that whilst
the prompts for the ASK fields are on screen you can see the document behind
and where the bookmark for the ASK fields are it displays "Error Bookmark not
Defined" - however when they are all filled in the error disappears and the
data that was typed in the boxes appears in the correct fields, but I can't
have users seeing the error messages it would confuse them.

I have tried all sorts of ways but cannot find how to hide the window whilst
the fields are updating.  I've tried Application.ScreenUpdating = False, but
it didn't work.  Anyone have an idea?

The code is:

Sub AutoNew()

Dim oStory As Range

   For Each oStory In ActiveDocument.StoryRanges
   oStory.Fields.Update
       If oStory.StoryType <> wdMainTextStory Then
           While Not (oStory.NextStoryRange Is Nothing)
           Set oStory = oStory.NextStoryRange
           oStory.Fields.Update
           Wend
       End If
   Next oStory
   Set oStory = Nothing
   
           Selection.GoTo What:=wdGoToBookmark, Name:="StartDoc"

End Sub

Thanks for looking at this.
Jeanmac
Jezebel - 20 Sep 2005 11:02 GMT
Why not use ordinary form fields? Then you wouldn't need the macro or the
updating at all... Break the document into sections, and protect only the
sections containing the fields.

>I have designed a report template using ASK fields (the report cannot be
> protected and tables are not practical).  A macro placed in the
[quoted text clipped - 40 lines]
> Thanks for looking at this.
> Jeanmac
jeanmac - 20 Sep 2005 15:18 GMT
Trouble is if I do that the document is protected and has reduced
functionality which is not what the users want.  The reason why I used ASK
fields is because the bookmark is inserted twice to update information in the
footer and on the back page of the document.  Hence the reason for wanting to
know if I can do anything with the bookmarks when the document first opens.

> Why not use ordinary form fields? Then you wouldn't need the macro or the
> updating at all... Break the document into sections, and protect only the
[quoted text clipped - 44 lines]
> > Thanks for looking at this.
> > Jeanmac
Jezebel - 21 Sep 2005 05:12 GMT
What reduced functionality? You need protect only the *sections* containing
the fields: the other sections can be unprotected and fully functional.

> Trouble is if I do that the document is protected and has reduced
> functionality which is not what the users want.  The reason why I used ASK
[quoted text clipped - 55 lines]
>> > Thanks for looking at this.
>> > Jeanmac
jeanmac - 21 Sep 2005 11:56 GMT
As far as I am aware,when part of a document is protected, you can't do some
things like formatting bullets and numbers, restart numbering, continue
numbering and other things.  It would be great if you know of a way of that
not happening.

> What reduced functionality? You need protect only the *sections* containing
> the fields: the other sections can be unprotected and fully functional.
[quoted text clipped - 58 lines]
> >> > Thanks for looking at this.
> >> > Jeanmac
Jezebel - 22 Sep 2005 09:13 GMT
Only in the protected section. The rest is fine. Designing the document
around that constraint is a hell of a lot easier than running macros on
other people's computers.

> As far as I am aware,when part of a document is protected, you can't do
> some
[quoted text clipped - 77 lines]
>> >> > Thanks for looking at this.
>> >> > Jeanmac
Charles Kenyon - 23 Sep 2005 03:41 GMT
Also, you do not have access to any of the headers and footers, even in
unprotected sections, when part of the document is protected for forms.
Signature

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

> Only in the protected section. The rest is fine. Designing the document
> around that constraint is a hell of a lot easier than running macros on
[quoted text clipped - 81 lines]
>>> >> > Thanks for looking at this.
>>> >> > Jeanmac
macropod - 22 Sep 2005 10:48 GMT
Hi jeanmac,

The *really* simple solution is to insert the bookmarks created/maintained
by the ASK fields into your template manually. For example, say you have a
field:
{ASK Age "How old are you?"}
Position the cursor immediately before this field, with nothing selected,
and use Insert|Bookmark to insert an 'Age' bookmark at that point. In fact,
you can insert these anywhere in the template, but next to the fields is
handy.

Do this with all of the fields but DON'T UPDATE THEM before saving the
template. If you do, you'll have to repeat the above process.

Now, when the template is opened, you won't get the "Error Bookmark not
Defined" message, but the required prompts will occur.

Cheers

> I have designed a report template using ASK fields (the report cannot be
> protected and tables are not practical).  A macro placed in the ThisDocument
[quoted text clipped - 32 lines]
> Thanks for looking at this.
> Jeanmac
jeanmac - 22 Sep 2005 16:40 GMT
Thanks macropod!  I got round it in the end by giving a default of an empty
text string to all the fields, but that's a bit excessive, your solution is
much better.

> Hi jeanmac,
>
[quoted text clipped - 59 lines]
> > Thanks for looking at this.
> > Jeanmac
slicknick - 28 Oct 2005 11:29 GMT
Hi jeanmac and macropod,

I've got the same problem in wanting to use ASK fields to obtain data when a
document template opens. I've created the ASK fields to store the input and
REF fields to use the values returned in multiple places within the document.
My problem is that I'm not prompted by the ASK fields when the document
opens. I've checked to see if I have any values specified for the ASK
variables by looking on Insert/Bookmark.. and there's nothing. Is there
something else I need to do to get the ASK fields to prompt me when the
document opens? All I see for me REF entries now is "ERROR! Reference source
not found."

TIA

> Thanks macropod!  I got round it in the end by giving a default of an empty
> text string to all the fields, but that's a bit excessive, your solution is
[quoted text clipped - 18 lines]
> >
> > Cheers
jeanmac - 28 Oct 2005 11:55 GMT
Hi Slicknick

In addition to writing the ASK fields, after a lot of help from the people
on this site (thankyou all), I found that I had to put a macro in the This
Document module of the template.  To get to it, in the template, click on the
Tools menu, select Macro then Visual Basic Editor.  

On the left of the Visual Basic Editor there is a Project Explorer window
and you will see something like Project (Template #), under the folder
Micrososft Word Objects you will see a template symbol labelled ThisDocument.
Double directly on the template symbol to open the module window for
ThisDocument and paste in the following code:

Sub AutoNew()

Dim oStory As Range

   For Each oStory In ActiveDocument.StoryRanges
   oStory.Fields.Update
       If oStory.StoryType <> wdMainTextStory Then
           While Not (oStory.NextStoryRange Is Nothing)
           Set oStory = oStory.NextStoryRange
           oStory.Fields.Update
           Wend
       End If
   Next oStory
   Set oStory = Nothing
   
       Selection.GoTo What:=wdGoToBookmark, Name:="StartDoc"

End Sub

Resave the template.  Hope that works, it did for me.

Cheers
Jeanmac

> Hi jeanmac and macropod,
>
[quoted text clipped - 32 lines]
> > >
> > > Cheers
slicknick - 28 Oct 2005 12:29 GMT
Jeanmac,

thanks for a very prompt response.

that certainly had an impact. I get a prompt now for one of the ASK fields I
have but not the others for some reason. I then get a MS Word error message
saying 'The bookmark does not exists' and that is followed by a VB error
saying the same thing. I know absolutely nothings about the language
structure for VB but I suspect that  the code that you gave me may relate to
individual ASK fields in your document. If that's the case, can you tell me
which bits I need to change.

TIA (again!)

> Hi Slicknick
>
[quoted text clipped - 32 lines]
> Cheers
> Jeanmac
jeanmac - 28 Oct 2005 12:57 GMT
Hi

It may be that the problem is in the Ref fields.  I didn't create Ref fields
where I wanted the ASK field to repeat.  What I did was place the cursor
where I wanted the field to repeat and press Ctrl+F9 to create the field
placemark {}, then I typed the ASK bookmark between them, eg if the ASK Field
prompts

{ ASK Country “Type the required country” \d “ “ \* MERGEFORMAT }

The bookmark is Country.  So at each place where you want the field repeated
type Ctrl+F9 to create the field placemark and then type the bookmark exactly
as it appears in the ASK field, eg {Country}.   Press Alt+F9 to reveal/hide
the ASK field codes and then you can copy it directly from the field.

Hope that helps.

Cheers
Jeanmac

> Jeanmac,
>
[quoted text clipped - 46 lines]
> > Cheers
> > Jeanmac
slicknick - 28 Oct 2005 13:32 GMT
Hi,

My ASK fields look OK and I've changed the places where I want the bookmarks
to be repeated so they don't use REF fields (although the MS Word Help seems
to indicate that is the way to do it). I want a value entered in the document
header on the first page and then that same value used elsewhere in the
document. So, the first time I want the value printed I also ASK for it:

{ ASK Machine_Type "Machine type booked/supplied?" \d ""}{ Machine_Type }

and then further on in the document I just have:

{ Machine_Type }

I still get the same problem 'Bookmark not found' errors using the VB code
you supplied. Do I need to change that at all for my bookmark names? If so,
which bits.

Thanks.

> Hi
>
[quoted text clipped - 66 lines]
> > > Cheers
> > > Jeanmac
jeanmac - 28 Oct 2005 13:43 GMT
Sorry!!!  I've just looked at the code, and the problem is that I had an
extra bookmark and told the code to go to it when it had finished running.
You need to take that line out of the MyDocument code, it is:

Selection.GoTo What:=wdGoToBookmark, Name:="StartDoc"

I didn't think and just copied all of the code from my document.  Hope this
fixes it for you.

Jeanmac

> Hi,
>
[quoted text clipped - 86 lines]
> > > > Cheers
> > > > Jeanmac
slicknick - 28 Oct 2005 14:48 GMT
OK. I've removed that line of code and that has resolved the 'Bookmark not
found' pop-up errors from Word and VB. The only issues I have now are:

1) I still get an 'ERROR! Bookmark not defined.' error message in the
document for the first reference of the bookmark which happens to be on the
same page (page 1)  as the ASK field itself. The second reference to the
bookmark (on page 3) is updated OK.

2) I only get a prompt for the first ASK field in the document. This
obviously then causes 'bookmark not defined' errors later. I've tried varying
the order of the ASK statement and proved that it is just the first one that
is prompted.

Have you any ideas about this?

Thanks.

> Sorry!!!  I've just looked at the code, and the problem is that I had an
> extra bookmark and told the code to go to it when it had finished running.
[quoted text clipped - 97 lines]
> > > > > Cheers
> > > > > Jeanmac
slicknick - 28 Oct 2005 14:49 GMT
OK. I've removed that line of code and that has resolved the 'Bookmark not
found' pop-up errors from Word and VB. The only issues I have now are:

1) I still get an 'ERROR! Bookmark not defined.' error message in the
document for the first reference of the bookmark which happens to be on the
same page (page 1)  as the ASK field itself. The second reference to the
bookmark (on page 3) is updated OK.

2) I only get a prompt for the first ASK field in the document. This
obviously then causes 'bookmark not defined' errors later. I've tried varying
the order of the ASK statement and proved that it is just the first one that
is prompted.

Have you any ideas about this?

Thanks.

> Sorry!!!  I've just looked at the code, and the problem is that I had an
> extra bookmark and told the code to go to it when it had finished running.
[quoted text clipped - 97 lines]
> > > > > Cheers
> > > > > Jeanmac
jeanmac - 28 Oct 2005 15:06 GMT
If you only have one actualk ASK field, although there are several references
to the bookmark, you will only have one prompt.  Try removing the bookmark
that gives the error message and re-doing it, it may have become corrupt.

:0)

> OK. I've removed that line of code and that has resolved the 'Bookmark not
> found' pop-up errors from Word and VB. The only issues I have now are:
[quoted text clipped - 114 lines]
> > > > > > Cheers
> > > > > > Jeanmac
slicknick - 28 Oct 2005 16:50 GMT
Hi again,

I've been playing around with this a bit more. I have two ASK fields at the
start of the document in the header to define two bookmarks but I only get
prompted for one input and that is always the first ASK.
The first reference to each of the bookmarks after the ASK statements is in
the header itself on page 1 and I always get the 'bookmark not defined'
message for each of them.
The second reference to each bookmark is in the header on page 3 (this is a
different document section as page 2 does not use the same header) and
bookmark value that was entered on the ASK is displayed correct but the other
had the 'bookmark not defined' message (as I would expect as I've only been
prompted for input once).

I created a brand new template and put two ASK statements immediately after
the header with two references to each bookmark on the same page and that
works fine - even without the VB code you supplied. Once I proved this was OK
I put ASK statements in the document header and I got problems again. The
problem therefore seems to be related to ASK fields being located in the
document header itself.

The template I'm creating is only 3 pages long so I'll redesign it without
headers and test that fully.

I'll let you know.

Thanks for all your assistance and patience.

> If you only have one actualk ASK field, although there are several references
> to the bookmark, you will only have one prompt.  Try removing the bookmark
[quoted text clipped - 120 lines]
> > > > > > > Cheers
> > > > > > > Jeanmac
slicknick - 28 Oct 2005 19:45 GMT
Hi jeanmac,

a final update for you (and anyone else who's struggling with this).

I redesigned my template and put all my ASK fields immediately after the
header (it seemed sensible to group them all together - in my case). All
fields were prompted for as I wanted and all subsequent references to the
bookmark values were printed correctly in the end.

On the first attempt I still had the VB code you gave me included but using
that, I got the first prompt and after supplying a value I could see the main
document with 'bookmark not defined' error messages while the other prompts
were displayed.

I removed the VB code and tried again. This time, I got all the prompts to
start with and then the document was displayed with the correct values. Just
what I wanted.

Thanks again for your help.
Cheers.
jeanmac - 29 Oct 2005 00:01 GMT
Hi Slicknick

Glad you sorted things out.  The code I provided was to update fields in
headers and footers as well as in the document body which forces recognition
of the ASK fields, irrespective of whether you have put the bookmarks in the
body, header or footer.  The actual ASK fields should be placed in the
document body, not in the header/footer.

Anyway, as long as the end product is what you want, that is the reward.  

Cheers
Jeanmac

> Hi jeanmac,
>
[quoted text clipped - 16 lines]
> Thanks again for your help.
> Cheers.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.