Question Disable listbox selector

Knildon

Learning by Default
Local time
Today, 07:56
Joined
Jan 19, 2012
Messages
89
Hello again,
I have a listbox that I would like to use as an information only box. Is there a way to turn off the selector/highlighter in the box when someone clicks on it??
I've searched through the forum but didn't find any answers. Found a lot of other goodies that I've bookmarked in my brain for future reference though.
Thanks in advance for any help.
Still learning,
Don
 
Look at "DemoListBoxA2000.mdb" (attachment, zip).
Open Form1 and try. Look at VBA.
 

Attachments

Last edited:
Thanks MStef for the reply and the sample code but that is not quite what I was looking for. I tried to apply some of the code you sent to my listbox but didn't have any luck getting it to do what I want.
I tried the "lock" command but that still allows a row to be highlighted.
What I would like is if a user clicks on data in the listbox, the data does not get highlighted/chosen. In other words, the selection process for the listbox is disabled.
Don't know any other way to explain what I'm looking for.
Don
 
John,
As noted in my last post I tried that. It still highlighted the top data row of the listbox when the user clicked anywhere in the listbox.
Today, just for the halibut, I tried the lock command again and a strange thing happened. No highlight on any of the rows in the listbox!!! However it did put a dotted box around the data in the top row of the listbox. Does my Access program have a mind of its own or what??? Well I can live with that if that's the best I can get.
Thanks for the comment, it made me retry that lock setting.
Unless I read anymore about this, I'll leave well enough alone.
Knildon :)
 
Set .Locked=True and .Enabled =False
 
spikepl,
Thanks for your input. That did the trick. No more highlights, no more dotted lines, just a dead screen with info on it.
Case Closed! :D
 
Rut Roh,
I spoke to soon!! Changing "Enabled" to False kills all actions in the listbox including the scroll feature so now I can't see anything more than what is in the box. It doesn't allow scrolling through the list from top to bottom.
Oh well, I guess I'll go back to where I was and leave well enough alone.
Thanks again for all the help.
 
Rut Roh,
I spoke to soon!! Changing "Enabled" to False kills all actions in the listbox including the scroll feature so now I can't see anything more than what is in the box. It doesn't allow scrolling through the list from top to bottom.
Oh well, I guess I'll go back to where I was and leave well enough alone.
Thanks again for all the help.
Which is why I didn't suggest it in the first place ;)
 
Two things:

* You can always make the listbox look disabled by changing the Back Color to an appropriate shade of grey and keep the Locked property set to Yes.

* Regarding your original question (i.e. post 1):
Code:
Me.Listbox.Selected(Me.Listbox.ListIndex) = False
Me.Listbox = Null
... will deselect the row just selected if put in one of the relevant events, i.e. After Update, Before Update, Click.
 
vbaInet,
I actually have 4 listboxes with different Back Colors on each one so using the grey color won't work in this case.
I tried that code in my Listbox when I first received it from MStef and I didn't get it to work. I'll have to go back and try it again. Maybe yours is a liitle different than his was, I don't remember.
If I don't get the code to work I'll just use what I have.
Thanks for your comments and time. :)
 
You said you set the Enable property to False, when you do this the Back Color of a control becomes Grey. I thought you wanted this effect and at the same time have the listbox locked?

Just had a look at MStef's code, it's not the same. The ItemsSelected collection is for Multi-Select listboxes and if you're listbox's MultiSelect property is set to None, it may not work. Plus he's looping through the collection whereas I'm not looping at all.
 
vbaInet,
OK, let's go back to the beginning. What I was looking for was the following:
A populated Listbox that could be scrolled through so the user could see all the information listed in the box.
Also, if the user clicked on the Listbox, nothing happened. No highlights, no color changes, nothing to make the user think he needed to do something further.
I then found that by setting the Locked property to Yes I accomplished almost what I wanted. The Listbox still scrolled, it didn't highlight or change colors but it did put a dotted box around the top row of data. I figure I can live with that.
If I set the Enabled property to No, the user can no longer scroll through the data in the box. Also, my Listbox doesn't change color to the grey you spoke of. Mine just stays the color it was. I'm using Access 2000 if that matters??
I hope that clears everything up. I don't know any other way to explain it.
Thanks for your persistance in trying to make it work for me.
Through all of this I'm learning quite a bit and at 70 years old that's saying a lot!!
:)
 
Through all of this I'm learning quite a bit and at 70 years old that's saying a lot!!
:)
You're doing pretty well. :D I wonder if I'll be able to remember any of this stuff or even learn anything new when I get to your age, which is quite a long way away. :)

The dots you see is because the listbox currently has focus. Set focus to another control in the Got Focus event of the listbox.

* Create a button and call it cmdGetFocus
* Change the Back Style property of the button to Transparent and clear what's in the Caption property
* Put Me.cmdGetFocus.SetFocus in the Got Focus event of your listbox

You can use the button as described above or you can set focus to one of your existing controls or the the control that last had focus.

I hope that helps. :)
 
Hello again vbaInet,
I have never had any luck putting code in the event boxes such as Got Focus. I always get an error that tells me Access can't find the macro named ....whatever I type into that event box. I've tried all different formats, parenthesis, etc. with no luck.
What does work for me is to put [Event Procedure] in the event box then write code to do what I need done. This works for me:
Private Sub MyListBox_GotFocus()
Me.EnterNameTextBox.SetFocus
End Sub

That gets rid of the dotted box around the data and puts the focus back to where it belongs.
I now have exactly what I was looking for.
Thanks again for your examples and help.:D
Maybe we can end this one unless you have something else to add.
 
Glad we could help. :)
Maybe we can end this one unless you have something else to add.
I do, just one more thing. :D

What does work for me is to put [Event Procedure] in the event box then write code to do what I need done. This works for me:
Private Sub MyListBox_GotFocus()
Me.EnterNameTextBox.SetFocus
End Sub
So when we say add some code to an event, what you've done is what we mean. The only thing you can write direcly in that box is expressions and what I gave you was not an expression, it's code. This was just fyi for next time.
 
I always appreciate any help I can get.:)
Now you tell me I can't put code in those little boxes!!! ;) No wonder I had so much trouble getting things to work. HA! HA! I have 4 books here about Access and I get more info from the internet than I get out of those books. I think I'll sell them for firewood!!
Thanks again for all your help and keep up the good work. I learn something everyday from all of you just by getting on here and reading.
I guess now we can call this one solved.:D
See you all on the next go round.
Thanks.
 

Users who are viewing this thread

Back
Top Bottom