Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 07-29-2018, 08:51 AM
Flynny Flynny is offline Windows 10 Office 2016
Novice
 
Join Date: Jul 2018
Posts: 2
Flynny is on a distinguished road
Thumbs up Reference a Building block gallery control from another Field and insert text using If logic

Dear all,

I am using office 365 and I have inserted a building block gallery control which I have set up to insert a 1 2 3 or NI The tag name for the control is E1_ConditionRating

I have used the building blocks gallery so I can format the condition ratings as set out above.

I need to be able to use the If statement in a field on a different part of the word document:

If 1 "E1 " to be listed at the front of the document under condition rating 1 heading



If 2 "E1 " to be listed at the front of the document under condition rating 2 heading

If 3 "E1 " to be listed at the front of the document under condition rating 3 heading and also to be listed under the rear urgent section of the document.

If NI "E1 " to be listed at the front of the document under not inspected heading

my problem is referencing the building block data which presumably is identified by the tag name.

I am a very basic user of word and a cannot nest the if statements and do not know how to reference the data in the building block control.


I would really appreciate your help.

Kind regards

Flynny
Reply With Quote
  #2  
Old 07-30-2018, 12:59 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 2,564
gmayor is a jewel in the roughgmayor is a jewel in the roughgmayor is a jewel in the roughgmayor is a jewel in the rough
Default

As we have no idea how your document is laid out - the expressions

If 1 "E1 " to be listed at the front of the document under condition rating 1 heading
If 2 "E1 " to be listed at the front of the document under condition rating 2 heading
If 3 "E1 " to be listed at the front of the document under condition rating 3 heading and also to be listed under the rear urgent section of the document.
If NI "E1 " to be listed at the front of the document under not inspected heading

are meaningless.

It is also difficult to see the point of the building block gallery. A listbox control would be clearer, however the syntax you are looking for is as follows. Replace the message boxes with the appropriate actions



Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Select Case ContentControl.Range.Text
    Case "1"
        MsgBox "1 selected"
    Case "2"
        MsgBox "2 selected"
    Case "3"
        MsgBox "3 selected"
    Case "NI"
        MsgBox "NI selected"
    End Select
End Sub
__________________
Graham Mayor - MS MVP (Word)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 07-30-2018, 11:30 AM
Flynny Flynny is offline Windows 10 Office 2016
Novice
 
Join Date: Jul 2018
Posts: 2
Flynny is on a distinguished road
Thumbs up Reference a Building block gallery control from another Field and insert text using case logic

Thank you very much for your reply.

Sorry for the lack of clarity I did not think it needed further explanation as I just enter the condition rating on one page in a field and I want a message to be automatically inserted as set out previously.

I am writing a property condition report. Say the chimneystack section I find that the stacks are in good condition I would insert a 1 condition rating, this presumably would be input into a field, I want the statement "Section E1 Chimneystacks" to be automatically displayed under the condition rating 1 summary page at the front of the report.

I hope I can still impinge on your good nature by asking the following:

Will I be able to format the characters and numbers in the colours as shown previously?

Do I put your suggested code into a field in the document or will I need to do something else?

How do I reference the result of the case to show a statement in the summary section?

Thanking you in anticipation

Flynny
Reply With Quote
  #4  
Old 07-30-2018, 08:34 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 2,564
gmayor is a jewel in the roughgmayor is a jewel in the roughgmayor is a jewel in the roughgmayor is a jewel in the rough
Default

The problem is that we have no idea what your document looks like. VBA does not work in vague concepts. From your latest comment it seems that you want to use this field more than once in the document. While that would be possible, the code I posted (which goes in the ThisDocument module of the template) would have to be modified to address each of those fields. So without knowing how many fields you have and their tags/titles, and given your limited VBA ability to modify code concepts, that is not going to be easy.

Can you post an example document that shows what you are selecting and how its result should appear.

FWIW you cannot display multiple colours in a content control list box, but you can display multiple colours as an output to they document based upon the selection. The code I posted would work with a building block gallery content control.
__________________
Graham Mayor - MS MVP (Word)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Word - Building Block (AutoText) - Array - Replace Text with Specific Building Blocks jc491 Word VBA 7 01-03-2016 10:34 PM
How-to: Add a quickpart, field or Building Block Gallery Content Control based on a UserForm HighSierra Word VBA 0 05-06-2015 08:20 PM
Using Building Block Gallery Content function on a form with restricted editing wes228 Word VBA 1 08-28-2014 08:14 AM
how to make building block content control determine bb to display elsewhere jamles12 Word VBA 5 11-16-2013 11:38 AM
Building blocks show correctly in dropdown, but wrong building block populates in doc wordgirl123 Word 0 10-03-2013 08:30 AM


All times are GMT -7. The time now is 07:24 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft