Move through a list box.

  • Thread starter Thread starter Jarryd
  • Start date Start date
J

Jarryd

Hi,

I have an unbound list box that is populated by a query. Clicking on a
value in the list box moves to the record in the recordset that matches the
value chosen in the list with a specified field:

Private Sub lstBill_List_AfterUpdate()
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Bill] = '" & Me!lstBill_List & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub

Now that is working well. The next thing I have done is created a procedure
triggered by the Click event of a button to add a value to the table that is
queried to populate the list box. So the value is added and the list box
requeried. I have also got the form to move to the newly created record.
What I can't do is get the list box to move its position to the newly added
value. Does anyone know how you move through items in an unbound list box?

TIA,

Jarryd
 
Try this

lstBill_List.Value = TheNewBillValue
lstBill_List.Selected(lstBill_List.ListIndex) = True

Basically two steps. First set the value of the list box to the newly
created record ID and then make that row the selected item in the list.
 
Hi Ron,

Well it is definately doing something. But it moves it to the ID in the
list that relates the previous record.

I did the following to test it:

Created a text box called txtBillHdn bound to the Bill field (the list box
contains a list of Bill numbers). Created a button called btnTstLst. On
the click event of btnTstLst I inserted your code:

Private Sub btntstLst_Click()

lstBill_List.Value = txtBillHdn
lstBill_List.Selected(lstBill_List.ListIndex) = True

'Basically two steps. First set the value of the list box to the newly
'created record ID and then make that row the selected item in the list.

End Sub

Then I went back to the form and used the navigator to go to record 4 with
a Bill value of 444444444. Textbox txtBillHdn is now 444444444. So I click
on btntstLst and it selects 333333333 from the list, the Bill value for
record 3. Any idea why that might be happening? Definately on the right
track though, the list selection is moving up and down.

TIA,

Jarryd

Ron Weiner said:
Try this

lstBill_List.Value = TheNewBillValue
lstBill_List.Selected(lstBill_List.ListIndex) = True

Basically two steps. First set the value of the list box to the newly
created record ID and then make that row the selected item in the list.

--
Ron W
www.WorksRite.com
Jarryd said:
Hi,

I have an unbound list box that is populated by a query. Clicking on a
value in the list box moves to the record in the recordset that matches the
value chosen in the list with a specified field:

Private Sub lstBill_List_AfterUpdate()
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Bill] = '" & Me!lstBill_List & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub

Now that is working well. The next thing I have done is created a procedure
triggered by the Click event of a button to add a value to the table that is
queried to populate the list box. So the value is added and the list box
requeried. I have also got the form to move to the newly created record.
What I can't do is get the list box to move its position to the newly added
value. Does anyone know how you move through items in an unbound list box?

TIA,

Jarryd
 
Sounds like you might have the ColumnHeads property set to True. If that is
the case you can either set the property to false or try changing :

lstMyListBox.Selected(lstMyListBox.ListIndex ) = True
to:
lstMyListBox.Selected(lstMyListBox.ListIndex + 1) = True

and see if that makes the problem go away.
--
Ron W
www.WorksRite.com
Jarryd said:
Hi Ron,

Well it is definately doing something. But it moves it to the ID in the
list that relates the previous record.

I did the following to test it:

Created a text box called txtBillHdn bound to the Bill field (the list box
contains a list of Bill numbers). Created a button called btnTstLst. On
the click event of btnTstLst I inserted your code:

Private Sub btntstLst_Click()

lstBill_List.Value = txtBillHdn
lstBill_List.Selected(lstBill_List.ListIndex) = True

'Basically two steps. First set the value of the list box to the newly
'created record ID and then make that row the selected item in the list.

End Sub

Then I went back to the form and used the navigator to go to record 4 with
a Bill value of 444444444. Textbox txtBillHdn is now 444444444. So I click
on btntstLst and it selects 333333333 from the list, the Bill value for
record 3. Any idea why that might be happening? Definately on the right
track though, the list selection is moving up and down.

TIA,

Jarryd

Ron Weiner said:
Try this

lstBill_List.Value = TheNewBillValue
lstBill_List.Selected(lstBill_List.ListIndex) = True

Basically two steps. First set the value of the list box to the newly
created record ID and then make that row the selected item in the list.

--
Ron W
www.WorksRite.com
Jarryd said:
Hi,

I have an unbound list box that is populated by a query. Clicking on a
value in the list box moves to the record in the recordset that matches the
value chosen in the list with a specified field:

Private Sub lstBill_List_AfterUpdate()
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Bill] = '" & Me!lstBill_List & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub

Now that is working well. The next thing I have done is created a procedure
triggered by the Click event of a button to add a value to the table
that
is
queried to populate the list box. So the value is added and the list box
requeried. I have also got the form to move to the newly created record.
What I can't do is get the list box to move its position to the newly added
value. Does anyone know how you move through items in an unbound list box?

TIA,

Jarryd
 
Nailed it. Right on my man.

TFYH!!!

Jarryd

Ron Weiner said:
Sounds like you might have the ColumnHeads property set to True. If that
is
the case you can either set the property to false or try changing :

lstMyListBox.Selected(lstMyListBox.ListIndex ) = True
to:
lstMyListBox.Selected(lstMyListBox.ListIndex + 1) = True

and see if that makes the problem go away.
--
Ron W
www.WorksRite.com
Jarryd said:
Hi Ron,

Well it is definately doing something. But it moves it to the ID in the
list that relates the previous record.

I did the following to test it:

Created a text box called txtBillHdn bound to the Bill field (the list
box
contains a list of Bill numbers). Created a button called btnTstLst. On
the click event of btnTstLst I inserted your code:

Private Sub btntstLst_Click()

lstBill_List.Value = txtBillHdn
lstBill_List.Selected(lstBill_List.ListIndex) = True

'Basically two steps. First set the value of the list box to the newly
'created record ID and then make that row the selected item in the list.

End Sub

Then I went back to the form and used the navigator to go to record 4 with
a Bill value of 444444444. Textbox txtBillHdn is now 444444444. So I click
on btntstLst and it selects 333333333 from the list, the Bill value for
record 3. Any idea why that might be happening? Definately on the right
track though, the list selection is moving up and down.

TIA,

Jarryd

Ron Weiner said:
Try this

lstBill_List.Value = TheNewBillValue
lstBill_List.Selected(lstBill_List.ListIndex) = True

Basically two steps. First set the value of the list box to the newly
created record ID and then make that row the selected item in the list.

--
Ron W
www.WorksRite.com
Hi,

I have an unbound list box that is populated by a query. Clicking on
a
value in the list box moves to the record in the recordset that
matches
the
value chosen in the list with a specified field:

Private Sub lstBill_List_AfterUpdate()
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Bill] = '" & Me!lstBill_List & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub

Now that is working well. The next thing I have done is created a
procedure
triggered by the Click event of a button to add a value to the table that
is
queried to populate the list box. So the value is added and the list box
requeried. I have also got the form to move to the newly created record.
What I can't do is get the list box to move its position to the newly
added
value. Does anyone know how you move through items in an unbound list
box?

TIA,

Jarryd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top