473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to select top recrod in a listbox by default

I need to have top record selected in my listbox when I load my form. Please help

Thanks
Jul 27 '10 #1

✓ answered by missinglinq

Actually, since the index is Zero-based, it would be (0) not (1) for the first item, and I believe you need to set focus to the listbox first:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.   ListBox1.SetFocus
  3.   Me.ListBox1.Selected(0) = True
  4. End Sub
Linq ;0)>

3 21557
munkee
374 256MB
Me.ListBox1.Selected(1) = True

Where listbox1 is the name of your listbox and (1) denotes the item number in your listbox to select.
Jul 27 '10 #2
missinglinq
3,532 Expert 2GB
Actually, since the index is Zero-based, it would be (0) not (1) for the first item, and I believe you need to set focus to the listbox first:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.   ListBox1.SetFocus
  3.   Me.ListBox1.Selected(0) = True
  4. End Sub
Linq ;0)>
Jul 27 '10 #3
Wow -- this simple post ended a long journey of frustration for me today! Awesome! If you have a listbox on a Tabbed Form (not subform) - see the following: I was using the Listbox as a navigation tool to select a records. Each tab's Listbox had a different query associated with it so it had different recordsets. When I would click on the tab it wouldn't change to the new recordset associated with the listbox for that tab/page. You must do the following to force the new recordset to be selected thus displaying the correct records. Note you must use an on change event for the tab control NOT the page. If you use an event associated with the page -- it is referencing the blank part of that page -- not the tab. Note: Tab control value is the page index it starts are zero not 1. So the example below is for my Page Index 1 which is the second page. Use the following for example:

Private Sub TabCtl0_Change()
If TabCtl0.Value = 1 Then
List1439.SetFocus
Me.List1439.Selected(0) = True
End If

End Sub
Sep 30 '10 #4

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

Similar topics

5
by: Coz | last post by:
Hi all, I'm looking for help again!!! I have been writing a page to update a database but now have another 'silly' problem with listbox's...Grrr... I'm trying to populate the list box with...
2
by: aman.coe | last post by:
hello all Consider this xml file: <root> <body> <ElementX id="X1" Xproperty="X_Default_Value" /> <ElementX id="X2" /> </body> </root>
5
by: Sigurd Bruteig | last post by:
Can I use a parameter from a listbox in a query. Something like SELECT tblTable.ID FROM tblTable WHERE Listbox1 LIKE items.selected Sigurd -- ____________________________________________...
1
by: BillyB | last post by:
I have a context menu tied to a list box. When I right-click on an item, I'd like that item to be selected before the context menu invokes, similar to how Outlook Express works when right-clicking...
1
by: Pawan Singh | last post by:
Hi, Is it possible to select a list box item when someone right clicks on it? I can find the snippets of code for VB6 but that code will not work in VB.Net. Thanks Pawan
8
by: daddydfsu via AccessMonster.com | last post by:
I am trying to create a ListBox based on a search from a TextBox. I have a TextBox where I will enter in a MemberAlias. I want to click on a Search Button and that will do a select from a...
6
by: Mokka | last post by:
Hi, I have this listbox and I would like to lock some of the lines so that the user can't select them. It's the 2 main areas "2798 Mokka" and "3892 Juice" I don't won't the user to be able to...
1
by: tahirakramch | last post by:
Dear Experts I have a select menu lets say <select id="textAds" name="textAds" multiple="true" > <option value="3">Zingar Burger</option> <option value="5">Pakistani Biryani</option> ...
2
by: 6afraidbecause789 | last post by:
Hi - Has anyone ever used toggle buttons to select items in a listbox? I'd like to put about 24 toggle buttons on an unbound form that select or deselect items in a multiple select listbox. I've...
3
by: muiz123 | last post by:
for the select element, if use click the left arrow key, then the select index will be changed, I want to cancel this default event, how can I do? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.