Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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
 

Thread Tools
Display Modes


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 03:02 AM.


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