![]() |
|
|
|
#1
|
||||
|
||||
|
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 |
|
#2
|
|||
|
|||
|
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
|
|
| Tags |
| form, vba, word 2013 |
|
|
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 combobox content to header
|
wpryan | Word VBA | 3 | 07-17-2015 01:44 AM |
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 |
how to populate textbox based on combobox selection in word
|
IvanGeorgiev | Word VBA | 1 | 02-21-2013 07:28 PM |