Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-23-2022, 10:55 AM
CSEShop CSEShop is offline Using a dropdown box to fill out multiple text fields and insert a bb image Windows 10 Using a dropdown box to fill out multiple text fields and insert a bb image Office 2013
Novice
Using a dropdown box to fill out multiple text fields and insert a bb image
 
Join Date: Dec 2022
Posts: 2
CSEShop is on a distinguished road
Default Using a dropdown box to fill out multiple text fields and insert a bb image

Hi, I am trying to create a form which has a single dropdown box that fills out multiple text fields and inserts an image all from 1 drop down box.

I am very unfamiliar with VBA, but I have been reading a lot of posts here and I've found two chunks of code that work in two separate documents how I would like them to (one fills out the text, the other inserts an image from a building block), but I cannot seem to figure out how to combine them in one document without breaking everything.

The first method I would like to use for adding the text fields is from this post and works exactly how I would perfer.:
https://www.msofficeforums.com/word-...html#post46903

Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Application.ScreenUpdating = False
Dim i As Long, StrDetails As String
With ContentControl
  If .Title = "Client" Then
    For i = 1 To .DropdownListEntries.Count
      If .DropdownListEntries(i).Text = .Range.Text Then
        StrDetails = .DropdownListEntries(i).Value
        Exit For
      End If
    Next
    If StrDetails = "" Then StrDetails = "||"
    With ActiveDocument.SelectContentControlsByTitle("Title")(1)
      .LockContents = False
      .Range.Text = Split(StrDetails, "|")(0)
      .LockContents = True
    End With
    With ActiveDocument.SelectContentControlsByTitle("Corporation of Firm Nme")(1)
      .LockContents = False
      .Range.Text = Split(StrDetails, "|")(1)
      .LockContents = True
    End With
    With ActiveDocument.SelectContentControlsByTitle("Address")(1)
      .LockContents = False
      .Range.Text = Split(StrDetails, "|")(2)
      .LockContents = True
    End With
  End If
End With
Application.ScreenUpdating = True
End Sub



The second part I want to combine to work with the first chunk of code is
from this post, I know that this post it talking about text building blocks, but I played with it and can reference image building blocks and it seems to work fine :
https://www.msofficeforums.com/word-...dent-drop.html

I'd also like to change the cc name from conditional content to signature, but that seems to break it for some reason

Code:
Option Explicit

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
  Select Case ContentControl.Title
    Case "Client"
      Select Case ContentControl.Range.Text
        Case "A": InsertBB_atRTCC_Range "Conditional Content", "Signature1"
        Case "B": InsertBB_atRTCC_Range "Conditional Content", "Signature2"
        '...so on.
        Case Else: InsertBB_atRTCC_Range "Conditional Content":
      End Select
  End Select
lbl_Exit:
  Exit Sub
End Sub

Sub InsertBB_atRTCC_Range(CCTitle As String, Optional BBName As String = vbNullString)
Dim oTmp As Template
Dim oRng As Range
Dim oTbl As Table
  Set oTmp = ThisDocument.AttachedTemplate
  Set oRng = ActiveDocument.SelectContentControlsByTitle(CCTitle).Item(1).Range
  'Tables in range and be problamatic so delete them.
  If oRng.Tables.Count > 0 Then
    For Each oTbl In oRng.Tables
      oTbl.Delete
    Next oTbl
    Set oRng = ActiveDocument.SelectContentControlsByTitle(CCTitle).Item(1).Range
  End If
  If Not BBName = vbNullString Then
    oTmp.BuildingBlockEntries(BBName).Insert oRng, True
  Else
    oRng.Text = vbNullString
  End If
lbl_Exit:
  Exit Sub
End Sub
Sub InsertBB_atBookmarkRange_Range(BMName As String, Optional BBName As String)
Dim oTmp As Template
Dim oRng As Range
Dim oTbl As Table
  Set oTmp = ThisDocument.AttachedTemplate
  Set oRng = ActiveDocument.Bookmarks(BMName).Range
  'Tables in range and be problamatic so delete them.
  If oRng.Tables.Count > 0 Then
    For Each oTbl In oRng.Tables
      oTbl.Delete
    Next oTbl
  End If
  If Not BBName = vbNullString Then
    Set oRng = oTmp.BuildingBlockEntries(BBName).Insert(oRng, True)
  Else
    oRng.Text = vbNullString
  End If
  ActiveDocument.Bookmarks.Add BMName, oRng
lbl_Exit:
  Exit Sub
End Sub


So I would like to have 1 dropdown box called client that when a client is selected it inputs text in the same way that the first chunk of code does, and ALSO inserts an image (signature) from a building block like the second chunk does. I can't figure out how to do both at once without breaking things and would really appreciate some help.
Reply With Quote
  #2  
Old 12-26-2022, 12:16 AM
gmayor's Avatar
gmayor gmayor is offline Using a dropdown box to fill out multiple text fields and insert a bb image Windows 10 Using a dropdown box to fill out multiple text fields and insert a bb image Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The attached should work, however I would suggest reading the signatures from disc rather than from building blocks as it makes them much easier to maintain. Put all the files in the same folder and create a new document from the template. The list is easily maintained using Insert Content Control Add-In and while this example could follow your proposal and have numbered signatures that reflect the list position of the selected name, it would be better if you named the signatures to match the listed names as in the attached.
Attached Files
File Type: zip Forum.zip (41.8 KB, 10 views)
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 12-27-2022, 02:17 PM
CSEShop CSEShop is offline Using a dropdown box to fill out multiple text fields and insert a bb image Windows 10 Using a dropdown box to fill out multiple text fields and insert a bb image Office 2013
Novice
Using a dropdown box to fill out multiple text fields and insert a bb image
 
Join Date: Dec 2022
Posts: 2
CSEShop is on a distinguished road
Default

Thank you so much! This is exactly what I was hoping to achieve, and you are right, storing the signatures like that is a much easier and better solution. I just tested this out and it works exactly as I was hoping to be able to do it. I was struggling quite a bit with this before posting and this was a great solution.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a dropdown box to fill out multiple text fields and insert a bb image Auto-Updating Text Fields in Form Fill doc strodden Word 2 08-28-2017 07:01 AM
Using a dropdown box to fill out multiple text fields and insert a bb image How to populate dependent dropdowns and auto-fill text fields simultaneously? vera Word VBA 1 10-07-2016 07:41 PM
Using a dropdown box to fill out multiple text fields and insert a bb image Dropdown boxes to multiple fields? Nukedaddy Word 3 09-16-2016 06:50 AM
Using a dropdown box to fill out multiple text fields and insert a bb image Question about multiple fill-in fields with the same answer Blades2002 Word 2 08-31-2015 11:20 AM
Using Fill In Fields to Autopopulate Multiple Areas in the Document rogelinepaula Word 1 08-13-2015 11:15 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:35 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft