Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    First Item In List (A2000)

    On opening a form which contains a list box, I need the first item in the list to be selected (Highlighted).
    I've seen it done, but don't know the syntax.

  2. #2
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: First Item In List (A2000)

    The syntax will depend on whether the listbox is single-select or multi-select, and whether or not there are column headings. Some examples shown below:

    Private Sub Form_Open(Cancel As Integer)

    Dim n As Integer

    ' Single-select listbox:
    Me.lstCustomers = Me.lstCustomers.ItemData(1) 'Column headings
    Me.lstCustomers = Me.lstCustomers.ItemData(0) 'No Column headings

    ' Multi-select listbox (with column headings):
    Me.lstCustomers.Selected(1) = True

    ' Select 1st three items:
    For n = 1 To 3
    Me.lstCustomers.Selected(n) = True
    Next


    End Sub

    If there are no column headings, use 0 instead of 1 as an index (column headings are counted as a row).

    HTH

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: First Item In List (A2000)

    Dave,

    This can be done without code. Set the Default Value property of the list box to

    [lbxList].[ItemData](0)

    where lbxList is the name of the list box - substitute the name of your list box.

    Have a good New Year's Eve and best wishes for 2003.

  4. #4
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: First Item In List (A2000)

    Thank you both for the help.


    Don't have too much drink tonight !!

    Seriously a Happy New Year to all.

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: First Item In List (A2000)

    One caveat on this method (which is the one I generally use, BTW). If you have column headings turned on for the combo or listbox, you need to select item 1, because item 0 is the column heading.
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •