Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set row source of an unbound listbox....

Status
Not open for further replies.

JazzMan2

Programmer
Jul 1, 1999
9
US
I would like to list the current benefits of an employee (which are in a benefits table. Each benefit is a seperate field with a yes/no type.)<br>
<br>
I would really like to be able to refresh the list box for each individual employee. <br>
<br>
Is this Possible??<br>
<br>
Thanks JazzMan2
 
Never mind everyone, I figured it out. I found a simple solution. Instead of using two list boxes. I used one text box and list box. When I select an item it is then listed in the current benefits text box. <br>
<br>
This is the code:<br>
<br>
Dim items As Recordset<br>
Dim myform As Form<br>
Dim selection As String<br>
Dim iselected As Integer<br>
Dim iloop As Integer<br>
Dim iindex As Integer<br>
Dim LB As ListBox<br>
Dim list As TextBox<br>
<br>
Set myform = Forms!employees![SubBenefits].Form<br>
Set items = CurrentDb.OpenRecordset("benefits", dbOpenDynaset)<br>
<br>
Set list = myform!Txtbenefits<br>
Set LB = myform!Lbenefits<br>
<br>
items.MoveFirst<br>
iselected = 0<br>
iselected = LB.ItemsSelected.Count<br>
<br>
For iloop = 0 To (iselected - 1)<br>
iindex = LB.ItemsSelected(iloop)<br>
selection = LB.ItemData(iindex)<br>
list.Value = list.Value & vbNewLine + selection<br>
Next iloop<br>
<br>

 
I know you found a solution but consider the following...<br>
<br>
I assume you have two list boxes - one for employee and one for benefits.<br>
<br>
The benefits list box should have an underlying query. Modify this query to use the form's employee list box control as part of the criteria (use the builder/wizard).<br>
<br>
Modify the click event of the employee list box to execute a macro that re-queries the benefits list box.<br>
<br>
Also, you may want have the benefits list box disabled by default. Enable it when the employee list box is clicked. Disable it when the employee list box get the focus.<br>
<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top