ListBox (1 Viewer)

asamy

New member
Local time
Today, 22:55
Joined
Nov 9, 2023
Messages
5
Hello,
I have a problem and I hope someone can help me..
I have a listbox with 5 columns one of these is a boolean(yes /no) the 5th one, I would like to change the value from no to yes of the selected row (with click or button). can anyone help me?
Thank you
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:55
Joined
Oct 29, 2018
Messages
21,474
Hi. Welcome to AWF!
 

asamy

New member
Local time
Today, 22:55
Joined
Nov 9, 2023
Messages
5
@theDBguy ..Thank you
@MajP
Thanks for your quick response..
1. it's too much for the "program", I need something easy
2. yes it dose exist in table..
3. and 4 noooo
I need (if its possibile) easy and simple way by clicking on the row or vba code to change the value of the selected row/rows



I tried something some code but it went wrong

Thanks in advance

Samy
 

AccessBlaster

Registered User.
Local time
Today, 13:55
Joined
May 22, 2010
Messages
5,953
I have a listbox with 5 columns one of these is a boolean(yes /no) the 5th one, I would like to change the value from no to yes of the selected row (with click or button). can anyone help me?

Back in 2015 I had a similar issue with a listbox. I scabbed my solution from JohnBigBooty HERE. Below is my version of johnbigbooty's listbox.


1699547014327.png


1699547035951.png


I made it so only one form was open, not both.
HTH
Good luck with your project.
 

isladogs

MVP / VIP
Local time
Today, 21:55
Joined
Jan 14, 2017
Messages
18,230
Use the listbox after update event to run an update query
If the bound field is called Id and the Boolean field is B. it could look similar to this
The Boolean field value will toggle True/False as the row is clicked

Code:
Private Sub ListBox_AfterUpdate()

CurrentDb.Execute "UPDATE TABLE1 Set B=Not B WHERE Id = " & Me.ListBox & ";"
Me.ListBox.Requery
End Sub
 

asamy

New member
Local time
Today, 22:55
Joined
Nov 9, 2023
Messages
5
Good morning,
I apologize for the late reply..
thanks everyone, I tried the advice of isladogs unfortunately but gave a Runtime Error 3075: Syntax Error (missing operator) in query expression ID
my Table name is"TabScarico" listbox is "lista" and the Boolean fiels is "scaricato"
I appreciate your help and thank you

Samy
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:55
Joined
Sep 21, 2011
Messages
14,310
Good morning,
I apologize for the late reply..
thanks everyone, I tried the advice of isladogs unfortunately but gave a Runtime Error 3075: Syntax Error (missing operator) in query expression ID
my Table name is"TabScarico" listbox is "lista" and the Boolean fiels is "scaricato"
I appreciate your help and thank you

Samy
And you can't post what you tried to use? :(
 

asamy

New member
Local time
Today, 22:55
Joined
Nov 9, 2023
Messages
5
@Gasman
Thanks for the reply..

Thats what I tried to use

Use the listbox after update event to run an update query
If the bound field is called Id and the Boolean field is B. it could look similar to this
The Boolean field value will toggle True/False as the row is clicked

Code:
Private Sub ListBox_AfterUpdate()

CurrentDb.Execute "UPDATE TABLE1 Set B=Not B WHERE Id = " & Me.ListBox & ";"
Me.ListBox.Requery
End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:55
Joined
Sep 21, 2011
Messages
14,310
Show your exact code, what @isladogs wrote should work unless the listbox was not numeric.
 

Users who are viewing this thread

Top Bottom