Auto selecting the first item in a list box

wjburke2

Registered User.
Local time
Today, 17:51
Joined
Jul 28, 2008
Messages
194
Is there a way to make the first item in a list box the record displayed on the screen?

I have a data entry screen. The user selects a record to edit by selecting a Category from a Combo box then all the items under that Category are displayed in a list box. My problem is the displayed record on the form is not the first in the list box. The user must click on the list box to change the record pointer (Displayed record on the form). This has lead to some errors and not to happy people.

Private Sub cmbCategory_AfterUpdate()

lstItem.Requery
lstItem.SetFocus
lstItem.ListIndex = 0
Call lstItem_AfterUpdate

End Sub


Private Sub lstItem_AfterUpdate()
' Find the record that matches the control.
Dim RS As Object

Set RS = Me.Recordset.Clone
RS.FindFirst "[CamId] = '" & Me.lstItem & "'"
Me.Bookmark = RS.Bookmark

End Sub
 
isnt that what a list box is? how would your system know which record was needed until after the item was selected in the list box?

try hiding the data, until the listbox selection is made, then the confusion should be avoided.
 
You can use the ItemData property of the list, which exposes a zero based array of the elements in the bound column. Set the value of the control to the value of the first item in the ItemData array and then call your routine that handles the list update (or click or whatever)...
Code:
Me.List0 = Me.List0.ItemData(0)
List0_AfterUpdate
 

Users who are viewing this thread

Back
Top Bottom