{ IF (text4=â€â€,{ IF (text3=â€â€,{ IF (text2=â€â€,{text1},{text2})},{t.

G

Gery C. Fryns

I am trying to use a formula without much success. The purpose of the
formula is to show the value of a specific bookmark field depending on the
value of another bookmark field. In particular, I need to check if a field
(bookmark) is empty or not.
Let say that text1, text2 and text3 are bookmark fields, I tried without
success the following
{ IF (text1=â€â€,{text2}, {text3}) }
{ IF count(text1)=0,{text2},{text3})}
Therefore, there must be some syntax errors.
In reality, I have text1, text2, text3, text4, text5 and text6 and I am
searching for the last non empty bookmark field. At the end if I had to four
fields, I should have something like this:
{ IF (text4=â€â€,{ IF (text3=â€â€,{ IF
(text2=â€â€,{text1},{text2})},{text3})},{text4})}

Thank you for your reply.
Gery C. Fryns
 
G

Graham Mayor

If you use REF fields to display the bookmarks, you don't actually need the
REF bit or the quote marks, but they help sort out the syntax and yours is
wrong, and you are also using smart quotes rather than straight quotes!

{IF {REF text1} = "" "{REF text2}" "{REF text3}"}

ie if text 1 is empty enter the content of text2 otherwise enter the content
of text3

If you want to ensure that form fields are completed, you need a macro - see
http://www.gmayor.com/formfieldmacros.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Gery C. Fryns

Thank you for your help. However, It still does not work. I tried several
combination. I also tried with and without REF or/and quotes.
I did unchecked the smart quotes from AutoCorrectOption which did not change
the results. My example is still very simple, I am just triying to get the
value of the bookmark field where I want it (header). Here are three results
{ IF {REF Text8} = "" {Text8} {Text9}
The result is Text8}

{ IF { Text8} = "" {Text8} {Text9}
The result is Text8}

{ IF {Text8} = "" {Text8} {Text9}
The result is {Text9}

Therefore, it is still impossible to get the Text8 value.

Note that without the IF, it works fine. I have the following VBA which is
activated on exit and update the fields when I do a Print Preview.

Sub UpdateAllFields()
Dim aStory As Range
Dim aField As Field
For Each aStory In ActiveDocument.StoryRanges
For Each aField In aStory.Fields
aField.Update
Next aField
Next aStory
End Sub

I look forward for some suggestions.
Thank you.
Gery C. Fryns
 
G

Greg Maxey

Gery,

I meant to get back to you earlier. I think your problem is that if you are
using formfields then the Text1 field may never be truly empty. By defualt
a formfield is five spaces long. Try putting 5 spaces between your " "
(i.e., {IF{TEXT1} =" "{TEXT1}{TEXT2}} )and see if the situation doesn't
improve. I did here and I got the expected results.
 
G

Gery C. Fryns

Greg,
Thank you for your response. I made progress. Indeed I realized that I need
to do a CTRL 9 to get the curly parenthesis. I am one step closer. I still
have the hurdle about testing the blank field. I tried several things, but
it always displays the False Text. I tried "", " ", up to 5 space " ".
Here is my latest statement.
{ IF { { REF Text18 } = " " } { REF Text24 } { REF Text18 }}

What is wrong with this statement? Quotes, spaces???
Thank you.
Regards,
Gery C. Fryns
 
G

Greg Maxey

Gery,

At first glance it looks like you have too many fields code braces. In your
{{REF Text18}= " "} the outer set of braces are extraneous.

Have you unprotected your form and verified the bookmark names for the
variables you are using are in fact Text18 and Text24? Is calculate on exit
checked in the Text18 form field options dialog?

Using your example, the following should work.
{ IF{ Text18 } = " "{ text24 }{ Text18 } }
 
G

Gery C. Fryns

Great, I copied character for character and It works. Thank you.
Unfortunately, I am not done. I tried this following statement and,
unfortunately, it does not work. Any Idea.

{ IF{ Text19 } = " "{ IF { Text18 } = " "{ Text24 }{ Text18 }}{
Text19 } }

I am getting close to my final product. I am building a template for a
special report. The first section is the 'Title Page' which is actually a
form. Part of the form is the 'Revision Block', with the history of the
report. Each line of the Revision Block is a 'Revision Line'. I need to put
the latest Revision Date, one of the field of the Revision Line in the report
Header. Now, you see what I am doing, I am checking each date bookmark
fields on each Revision Line, and I am getting the latest Revision date.
This date will then appear in the header block of the Report Section 2. I
hope this explanation will provide a bit of substance to your work.
Thank you.
Regards,
Gery
 
G

Greg Maxey

Gery,

I don't see any problem with your formula construction. Note that fields
will not update in headers and footers using the form field calculate on
exit. Does you formula work if you place it in the the main body of the
document? If you have the formula in the header then you will need to
manually update the fields (if "update fields" is set in your print settings
this is easily done by simply toggling in and out of print preview).
Another option is to run a macro to update the fields. See:

http://www.gmayor.com/installing_macro.htm
 
G

Gery C. Fryns

Greg,
Indeed the formula works outside the header. Therefore, there must be a
problem with the VBA subroutine. I tried, without success, the following two
subroutines:

Sub UpdateAll()
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
End Sub

Sub UpdateAllFields()
Dim aStory As Range
Dim aField As Field
For Each aStory In ActiveDocument.StoryRanges
For Each aField In aStory.Fields
aField.Update
Next aField
Next aStory
End Sub

Unfortunately, I am not familiar enough with VBA to understand if these
subroutines would work or not with more involved formulae.
I would appreciate if you could help me further on this problem. Any
suggestion?
Thank you.
Regards,
Gery
 
G

Graham Mayor

Updating fields in headers/footers can be problematical. The codes you have
tried usually work, but occasionally they need a little more encouragement.
Does it work if you run the macro twice?

Try the following which addresses the header/footers directly.

Sub Update()
Dim oField As Field
Dim oSection As Section
Dim oHeader As HeaderFooter
Dim oFooter As HeaderFooter

For Each oSection In ActiveDocument.Sections
For Each oHeader In oSection.Headers
If oHeader.Exists Then
For Each oField In oHeader.Range.Fields
oField.Update
Next oField
End If
Next oHeader
For Each oFooter In oSection.Footers
If oFooter.Exists Then
For Each oField In oFooter.Range.Fields
oField.Update
Next oField
End If
Next oFooter
Next oSection
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Greg Maxey

Gery,

Graham provide as good or better answer than I could give.

Do you have File>Print>Options>Printing Options>Update Fields checked? What
happens if you toggle to and from print preview?
 
G

Gery C. Fryns

Graham,
I appreciate your interest in this matter very much.
The subroutine you sent, provides the following result in the header:
Try #1:
Text 24 = 01 Nov 01, Text 18= " ", Text19=" ",
The header shows 01 Nov 01
Try #2:
Text 24 = 01 Nov 01, Text 18= 02 Nov 02, Text19=" ",
The header shows ""
Try #3:
Text 24 = 01 Nov 01, Text 18= 02 Nov 02, Text19="03 Nov 03"
The header shows "03 Nov 03".

Therefore, there are some progress. However, Try #2 did not provide the
expected results.
Again the field statement is:
{ IF{ Text19 } = " "{ IF { Text18 } = " "{ Text24 }{ Text18}}{
Text19 } }
Again, the bookmark properties are all correct: subroutine name, check on
"compute on exit", etc.
I ll be glad to mail you the file if you are interested.
Thank you for trying.
Gery C. Fryns
 
G

Greg Maxey

Gery,

I have found something that works:

Since your formula is working in the document, set a bookmark value equal
the a formula result contained in the main body text. Something like:

{ SET "Result" { IF {Text19 } = " ""{ IF { Text18 } = " "{
Text24 }{ Text18 }}""{ Text19 }"}}

Then uses a REF field in the header. Like { Result }

Then run the following macro on exit from the Text18, Text19 and Text24 form
fields:

Sub UpdateFields()
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
End Sub
 
G

Gery C. Fryns

Greg,
YES, it works. Actually, I just tried to create a field outside the header
using hidden text, and it looks like the hidden effect under font format does
not work with field. Obviously, the SET "Result" resolves the issue. For
sure a small user guide on how to use field code and references would help
ignorant people like me. Any suggestion?
I would like to thank you, Greg Maxey, and also Graham Mayor and Charles
Kenyon for their patience helping me with this project.
Regards,
Gery C. Fryns, P.E.
 

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