The following example uses a range of worksheet cells in a ListBox and, when the user selects a row from the list, displays the row index in another worksheet cell. This code sample uses the RowSource, BoundColumn, and ControlSource properties.
To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains a ListBox named ListBox1. In the worksheet, enter data in cells A1:E4. You also need to make sure cell A6 contains no data.
Thanks. Can that also be done with an ADO data object. I would like to tie the fields to an access mdb. Also, do you know where I get the Calendar control files? I appreciate the help, this nudge should get me up and running.
Depending on how you wish to distribute your completed Workbook you may want to try using the controls from the Control Toolbar. Example; from your View ... ToolBars menu select Control ToolBox. Try using its ComboBox control. You can also customize this toolbar to include any Calendar Controls installed on your computer. Although I have never bound the ComboBox control to a RecordSet it can be populated directly with out need of first inserting the RecordSet values into cell ranges.
Example;
Sub Sample()
Dim dbSmpl as Database
Dim rsSmpl as Database
Dim strSQL as String
Dim WS as String 'WS = WorkSheet Name
WS = "Sheet1"
strSQL = "Select FName from Customers"
Set dbSmpl = OpenDatabase("Your Database Path & Name"
Set rsSmpl = dbSmpl.OpenRecordSet(strSQL)
Sheets(WS).ComboBox1.Clear
Do While rsSmpl.EOF = False
Sheets(WS).ComboBox1.Additem rsSmpl.Field("FName".value
rsSmpl.MoveNext
Loop
End Sub
NOTE: Again if your planning to distribute the workbook among a variety of workstations that are running varying versions of Office then this solution may not be the best.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.