By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,022 Members | 1,372 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,022 IT Pros & Developers. It's quick & easy.

Prompt selection to the last record in the list box

P: 56
Does anyone know how to write a code to promt the selection at the last record in the list box?. I have this code below in the "On Click" event, when user click on the code, it close a form, requery the list box, but then I would like the selection to be prompted at the last record.

Expand|Select|Wrap|Line Numbers
  1. DoCmd.Close acForm, "frmReview" 
  2. [Forms]![frmPatientAccount]![lstPtReview].Requery
  3. 'woud like to add here a line of code to prompt selection of the listbox to the last record.
Oct 12 '08 #1
Share this Question
Share on Google+
8 Replies

Expert 2.5K+
P: 3,532
Maybe something like:

Me.lstPtReview = Me.lstPtReview.ItemData(Me.lstPtReview.ListCount - 1)

Linq ;0)>
Oct 12 '08 #2

Expert Mod 15k+
P: 31,769
Indeed. Setting the record of a ListBox or ComboBox is done, rather bizarrely, by setting it to the value of one of them (as Linq's code does).
Oct 12 '08 #3

P: 56
thanks alot. It works so well.

Oct 12 '08 #4

P: 56
I've tried to change from -1 to 0 to prompt record to the first added record in the list, but it did not work, anybody can help?

[Forms]![frmPatientAccount]![lstPtReview] = [Forms]![frmPatientAccount]![lstPtReview].ItemData([Forms]![frmPatientAccount]![lstPtReview].ListCount(0))


what I would like to do is prompt the listbox to the newly added record since my list is sorted from Z to A, so the new record will be the first record in the list.

Mar 23 '09 #5

Expert 5K+
P: 8,706
Assuming your List Box is named lstTest, to Select the 'Last' entry:
Expand|Select|Wrap|Line Numbers
  1. Me![lstTest].Selected(Me![lstTest].ListCount - 1) = True
Mar 23 '09 #6

P: 56
Thanks for your help.
That's was my previous question. Now, the user would like to move it to the First record instead of the last, I've tried to change from -1 to 0 or 1, but nothing works well. I've tried other way such as GoToRecord,,acFirst, but nothing happens.

Any idea? Thanks alot!

Mar 23 '09 #7

Expert 100+
P: 489

Since you don't know the location of the last record you have to get the number from the count of records listed in the listbox.
Expand|Select|Wrap|Line Numbers
  1. (Me![lstTest].ListCount - 1)
But when trying to move to the first record you already know where the record is, it's the first one.
Expand|Select|Wrap|Line Numbers
  1. Me![lstTest].Selected(1) = True
Just be careful if it's a multiselect listbox as this won't deselect any previously selected items.
Mar 23 '09 #8

P: 56
my listbox is not a mutiselection. It's a single select list box. so it worked perfectly.
Thank you for your help.

Mar 23 '09 #9

Post your reply

Sign in to post your reply or Sign up for a free account.