LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Populate a ComboBox

I used the code shown below to populate a combobox in a Word UserForm.

It basically cycles through each record and loads the value of field
1, 2 or 3 into the combobox depending on a user selection.

Is there a way to use the combobox '.List" method to populate the list
all at once vice cycling through each record. Something like:

me.combobox.List = mySSRange Column 1

Thanks.

Private Sub UserForm_Initialize()
'You need to set a reference in your project to the
'"Microsoft DAO 3.51 (or 3.6) Object Library".
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i As Long
'Open a spreadsheet to retrieve data
Set db = OpenDatabase("C:\Book1", False, False, "Excel 8.0")
Set rs = db.OpenRecordset("SELECT * FROM `mySSRange`")
i = 0
'Loop through each recordset.
Me.ComboBox1.Clear
While Not rs.EOF
Select Case ActiveDocument.FormFields("Dropdown1").Result
Case "A"
Me.ComboBox1.AddItem rs.Fields(0).Value
Case "B"
Me.ComboBox1.AddItem rs.Fields(1).Value
Case "C"
Me.ComboBox1.AddItem rs.Fields(1).Value
End Select
rs.MoveNext
i = i + 1
Wend
'Clean up.
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Populate ComboBox with Enum [email protected] Excel Programming 0 February 1st 07 12:19 AM
use selected value from one combobox to populate another combobox rjudge[_7_] Excel Programming 3 April 14th 06 02:01 PM
Populate combobox Pat Excel Programming 1 December 10th 04 05:33 PM
Populate a combobox Rory[_3_] Excel Programming 2 June 9th 04 04:20 PM


All times are GMT +1. The time now is 07:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"