Consulting

Results 1 to 9 of 9

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
    429
    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
    Last edited by Aussiebear; Yesterday at 01:42 PM.
    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
    429
    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
    109
    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
    Last edited by Aussiebear; Yesterday at 01:43 PM.

  7. #7
    VBAX Contributor
    Joined
    Nov 2020
    Location
    Swansea,South Wales,UK
    Posts
    109
    Location
    I have no idea as to what you have just posted.
    Never heard of VBAX mentor, but of course you could have asked some AI like ChatGPT?

    Plus
    and the textfield must show me the selected LAST Id in the textbox.

    So you have not what you asked for at all?

  8. #8
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    429
    Location
    Gasman, VBAX mentor is me, per subtitle under my user name (yours is VBAX Contributor).

    They do have what they asked for. They want selected ID displayed in textbox - last when btn12 is clicked and first when btn11 is clicked.
    Last edited by June7; Yesterday at 07:16 PM.
    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.

  9. #9
    VBAX Contributor
    Joined
    Nov 2020
    Location
    Swansea,South Wales,UK
    Posts
    109
    Location
    Quote Originally Posted by June7 View Post
    Gasman, VBAX mentor is me, per subtitle under my user name (yours is VBAX Contributor).

    They do have what they asked for. They want selected ID displayed in textbox - last when btn12 is clicked and first when btn11 is clicked.
    Ah I see. Well done.
    Not the best way of saying who helped though?

Posting Permissions

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