Consulting

Results 1 to 6 of 6

Thread: Navigate in listbox

  1. #1
    VBAX Regular
    Joined
    Jan 2016
    Posts
    57
    Location

    Navigate in listbox

    Hello forum friend’s

    I have a form named Form1 and a table named Table1.
    In the form I have 2 command buttons named btn11 and btn12, also one textfield named id and a listbox named Lstbox.

    What i’am looking for when I click on btn12, (the LAST id in the listbox must be selected) and the textfield must show me the selected LAST Id in the textbox.

    When I click btn11 (the FIRST id in the listbox must be selected) and the textfield must show me the selected FIRST Id in the textbox.

    when these acttion occur all the id’s in the listbox must be visible.
    The listbox has 2 field named id and txt. The id is type Integer

    My id in the table is an autonumber field with No Primary Key.
    I tried to work with a qry named qryTable1 but it did not work.
    The option explicit is deactivated

    I’m tired, please give me guidance or solution because I cannot find it for myself. Forgive my english, it was many years ago when i went to school.

    Thanks, in advance
    TonC

  2. #2
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    428
    Location
    Select the last item:
    Me.Lstbox.Selected(Me.LstBox.ListCount - 1) = True

    Select the first item:
    Me.Lstbox.Selected(0) = True

    Expression in textbox to display ID: =Lstbox
    How to attach file: Reading and Posting Messages (vbaexpress.com), click Go Advanced below post edit window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    VBAX Regular
    Joined
    Jan 2016
    Posts
    57
    Location
    Its not working.
    btn12 select and mark the id number, but nothing showing in the textbox
    btn11 select id number (no mark), textfield remains empty

  4. #4
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    428
    Location
    Works for me.
    If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: Reading and Posting Messages (vbaexpress.com), click Go Advanced below post edit window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    VBAX Contributor
    Joined
    Nov 2020
    Location
    Swansea,South Wales,UK
    Posts
    107
    Location
    Why not give your controls meaningful names?

    6 months down the road, you will be very glad you did.

    Never leave off Option Explicit. That is just asking for trouble.

    If you cannot get it working, upload your db with enough to see the issue.

  6. #6
    VBAX Regular
    Joined
    Jan 2016
    Posts
    57
    Location
    Hi,
    With the guidance from VBAX mentor, I solved the puzzle the db is working now.
    Still the option explicit is de-activated.
    The code for surfing to first and last record told VBAX mentor was very good. So I worked to show the record in my texkfield.
    Here is the code as supplement from VBAX mentor:

      
                Me.Id.Value = lstBox.Column(0)
                  Me.txt.Value = lstBox.Column(1)

    Many thanks,
    Till next time,
    Ton

Posting Permissions

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