Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-21-2020, 07:04 PM
Visor Visor 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 2013
Advanced Beginner
Pass the selected in Combobox to a Textbox of a Word form
 
Join Date: Aug 2019
Posts: 38
Visor is on a distinguished road
Default Pass the selected in Combobox to a Textbox of a Word form

Dear forum members, greetings.


I have in a form in Word, a combobox and a textbox.
I don't know why my code doesn't work, I can't find the problem.
I have put .text or .value after combobox but it doesn't work

HTML Code:
Private Sub CommandButton1_Click()

Me.Textbo1.Text = Me.Combobox1.Text
'Me.Textbo1.Text = Me.Combobox1.value

End Sub
I select the data in a combobox and I want to pass this to a textbox, I execute with a button but nothing happens.
I ask for your support to solve this problem
I thank you in advance for your collaboration
Reply With Quote
  #2  
Old 07-21-2020, 07:52 PM
gmayor's Avatar
gmayor gmayor 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: Aug 2014
Posts: 4,101
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 of
Default

What sort of combobox and text box have you inserted? If you inserted ActiveX controls then assuming you have the names of the controls correct the code you have posted will work. Shouldn't Textbo1 be Textbox1?
__________________
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 07-21-2020, 10:38 PM
Visor Visor 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 2013
Advanced Beginner
Pass the selected in Combobox to a Textbox of a Word form
 
Join Date: Aug 2019
Posts: 38
Visor is on a distinguished road
Default

Regards
The textbox is well written, I wrote wrong in the question post ...
It is a form, not an Activex.
I have tried several times, it doesn't work
In Excel it works, in word it doesn't !!
I do not understand why?
Attached Images
File Type: jpg Combobox a Textbox.jpg (34.0 KB, 24 views)
Reply With Quote
  #4  
Old 07-22-2020, 12:17 AM
Guessed's Avatar
Guessed Guessed 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: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Firstly, verify you haven't changed the name of the button

Test the macro is firing and check the value in the combobox by using
Code:
Private Sub CommandButton1_Click()
  MsgBox Me.Combobox1.Text
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 07-22-2020, 12:32 AM
gmayor's Avatar
gmayor gmayor 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: Aug 2014
Posts: 4,101
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 of
Default

Can you post your document so we can see what is happening?
__________________
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
  #6  
Old 07-22-2020, 08:21 AM
Visor Visor 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 2013
Advanced Beginner
Pass the selected in Combobox to a Textbox of a Word form
 
Join Date: Aug 2019
Posts: 38
Visor is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
Can you post your document so we can see what is happening?


Greetings, I think something has to do with this module ... that I have to use a Listbox
Please before I can show a sample file

The name of the module is: mod_ExcelInteropSA

HTML Code:
Option Explicit
Public Function xlFillList(oListOrComboBox As Object, strWorkbook As String, _
                           bSuppressHeader As Boolean, strSQL As String, _
                           bSingleColumn As Boolean)
Dim oConn As Object
Dim oRecordSet As Object
Dim lngNumRecs As Long, lngIndex As Long
Dim strWidth As String
Dim strConnection As String

  
  
  'Create connection:
  Set oConn = CreateObject("ADODB.Connection")
  If bSuppressHeader Then
    strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                    "Data Source=" & strWorkbook & ";" & _
                    "Extended Properties=""Excel 12.0 Xml;HDR=YES"";"
  Else
    strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                    "Data Source=" & strWorkbook & ";" & _
                    "Extended Properties=""Excel 12.0 Xml;HDR=NO"";"
  End If
  oConn.Open ConnectionString:=strConnection
  Set oRecordSet = CreateObject("ADODB.Recordset")
  'Read the data from the worksheet.
  oRecordSet.Open strSQL, oConn, 3, 1 '3: adOpenStatic, 1: adLockReadOnly
  With oRecordSet
    'Find the last record.
    .MoveLast
    'Get count.
    lngNumRecs = .RecordCount
    'Return to the start.
    .MoveFirst
  End With
  With oListOrComboBox
    .Clear
    'Load the records into the columns of the named list/combo box.
    .ColumnCount = oRecordSet.Fields.Count
    .Column = oRecordSet.GetRows(lngNumRecs)
    strWidth = vbNullString
    If bSingleColumn Then
     'Set the widths of the combo/list box columns to display only the first column.
      strWidth = .Width - 20 & " pt;"
      For lngIndex = 2 To .ColumnCount
        strWidth = strWidth & "0 pt"
        If lngIndex < .ColumnCount Then
          strWidth = strWidth & ";"
        End If
      Next lngIndex
    Else
      For lngIndex = 1 To .ColumnCount
        strWidth = strWidth & Val(.Width \ .ColumnCount) - 10 & " pt;"
      Next lngIndex
      .ColumnWidths = strWidth
    End If
  End With
Cleanup:
  If oRecordSet.State = 1 Then oRecordSet.Close
  Set oRecordSet = Nothing
  If oConn.State = 1 Then oConn.Close
  Set oConn = Nothing
lbl_Exit:
  Exit Function
End Function
Reply With Quote
  #7  
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,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
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
  #8  
Old 07-22-2020, 09:58 AM
Visor Visor 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 2013
Advanced Beginner
Pass the selected in Combobox to a Textbox of a Word form
 
Join Date: Aug 2019
Posts: 38
Visor is on a distinguished road
Default

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

Yes, indeed, the code that I put in the previous post was kindly provided by gmaxey, and I appreciate your support

so sorry, I'm very sorry

I used to think that that code could have something to do with the fact that I cannot use the combobox
Reply With Quote
  #9  
Old 07-22-2020, 10:23 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,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Using the combobox or not has more to do with what you are doing than with code others have provided you. Why don't you just send me the document and I will look at it for you.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #10  
Old 07-22-2020, 03:25 PM
Visor Visor 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 2013
Advanced Beginner
Pass the selected in Combobox to a Textbox of a Word form
 
Join Date: Aug 2019
Posts: 38
Visor is on a distinguished road
Default

Greetings, I already discovered the problem. Indeed the code that you have provided me worked as expected. I have already resolved the issue
I greatly appreciate the support I have received ...
Reply With Quote
  #11  
Old 07-24-2020, 08:38 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,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

When you post a problem and solve it, why not post the solution?
__________________
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 02:00 AM.


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