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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting item in a listbox

Status
Not open for further replies.

BananaQuaaludes

Programmer
Jun 17, 2003
6
US
Hello,

I am having a problem with an Access listbox - I need to select the first (or any) item in the listbox. I used the

[listbox].selected(0) = true

method, which works. Only problem is, my form freezes up. I can't select anything else, on any control on the form.

Any help would be greatly appreciated.
 
Where is the listbox.selected(0) = true code located?


Randy
 
Hello Randy700,

I'm populating the listbox on form open. I want to select the first item in that listbox, because it determines child data in the other listboxes, seen below in Sub Populate()

Private Sub cboReportID_Click()
Call Populate
End Sub

Private Sub Form_Open(Cancel As Integer)
Call Populate
End Sub

Sub Populate()

Dim ReportID As Integer

'reports
Me.cboReportID.RowSource = strSQL_Reports
'pick the first report
If cboReportID.ListIndex = -1 Then
Me.cboReportID.Selected(0) = True
End If

ReportID = Me.cboReportID.ItemData(Me.cboReportID.ListIndex)

'users
lstReport.RowSource = strSQL_ReportUsers(ReportID)
'prompts
lstReportPrompts.RowSource = strSQL_ReportPrompts(ReportID)
'status
Me.fraStatus.Value = strSQL_ReportStatus(ReportID)

End Sub
 
Hi BananaQuaaludes,

do your call in Form_Load instead of Form_Open

the following will work...
Code:
Private Sub Form_Load()
    Me.Listbox.Selected(0) = True
End Sub

the following will make your form freeze has you have already experienced.
Code:
Private Sub Form_Open()
    Me.Listbox.Selected(0) = True
End Sub

Cheers
:)Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top