Log in

View Full Version : [SOLVED:] Navigate in listbox



TonC
06-14-2025, 02:49 PM
Hello forum friend’s :hi:

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 : pray2:
TonC

June7
06-14-2025, 04:56 PM
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

TonC
06-15-2025, 01:50 AM
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

June7
06-15-2025, 09:22 AM
Works for me.
If you want to provide db for analysis, follow instructions at bottom of my post.

Gasman
06-15-2025, 11:33 AM
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.

TonC
06-15-2025, 12:50 PM
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

Gasman
06-15-2025, 02:11 PM
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? :(

June7
06-15-2025, 05:20 PM
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.

Gasman
06-16-2025, 02:40 AM
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? :(