Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-22-2020, 09:07 AM
gmaxey gmaxey is offline Pass the selected in Combobox to a Textbox of a Word form Windows 10 Pass the selected in Combobox to a Textbox of a Word form Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

When you post code that someone else provided to you, you should at least acknowledge the source!


Have to use a ListBox???? oListOrComboBox as object should make it pretty clear that you can use a List or ComboBox!!!




Regardless, writing the value selected in a listbox to a textbox has little to do with how that listbox was populated.


Code:
Private Sub UserForm_Initialize()
  With ListBox1
    .AddItem "A"
    .AddItem "B"
    .AddItem "C"
  End With
  With ListBox2
    .AddItem
    .List(.ListCount - 1, 0) = "A"
    .List(.ListCount - 1, 1) = "Apples"
    .AddItem
    .List(.ListCount - 1, 0) = "B"
    .List(.ListCount - 1, 1) = "Birds"
    .AddItem
    .List(.ListCount - 1, 0) = "C"
    .List(.ListCount - 1, 1) = "Cats"
  End With
End Sub

Private Sub CommandButton1_Click()
  TextBox1 = vbNullString
  TextBox2 = vbNullString
  If ListBox1.ListIndex <> -1 Then TextBox1 = ListBox1
  If ListBox2.ListIndex <> -1 Then TextBox2 = ListBox2 'Uses the bound column
  'Or use an explicit indexed column
  'If ListBox2.ListIndex <> -1 Then TextBox2 = ListBox2.Column(0)
  'If ListBox2.ListIndex <> -1 Then TextBox2 = ListBox2.Column(1)
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Tags
form, vba, word 2013

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a ComboBox in a Form that creates a new document and autofills a textBox BlackGirlMagic Word VBA 5 02-13-2017 02:39 PM
Pass the selected in Combobox to a Textbox of a Word form Pass combobox content to header wpryan Word VBA 3 07-17-2015 01:44 AM
Pass the selected in Combobox to a Textbox of a Word form Outlook 2007 Code For Matching Textbox to a Combobox in a Different Form lms Outlook 4 07-03-2013 08:34 AM
how to populate textbox based on combobox selection in word IvanGeorgiev Word 1 02-21-2013 07:32 PM
Pass the selected in Combobox to a Textbox of a Word form how to populate textbox based on combobox selection in word IvanGeorgiev Word VBA 1 02-21-2013 07:28 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:47 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