Select first item in listbox

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
2,819
Hi,
Currently when i open the ListBox1 its first entry shown is actualy the second entry.
Make sense ?
I need to pull the sliderdown to see the correct first entry.

Here is the code.
Ive tried various options but each time im still seeing the second.

VBA Code:
Private Sub ListBox1_Click()
    If ListBox1.ListCount > 0 Then
    ListBox1.ListIndex = 0
    End If
      Dim answer As Integer
 
  Range("A" & ListBox1.List(ListBox1.ListIndex, 1)).Select
  answer = MsgBox("OPEN DATABASE ?", vbYesNo + vbCritical, "OPEN DATABASE MESSAGE")
   If answer = vbYes Then
   Unload DatabaseNameSearch
   Database.Show

Else
    Unload DatabaseNameSearch
End If
End Sub
 

CSmith

Board Regular
Joined
Jan 13, 2020
Messages
158
Office Version
365, 2010, 2007
Platform
Windows, Mobile, Web
Multi-select listbox or?
 

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
2,819
I’m sure I tried that but still the second value was shown.
 

CSmith

Board Regular
Joined
Jan 13, 2020
Messages
158
Office Version
365, 2010, 2007
Platform
Windows, Mobile, Web
what are you attempting to do with that code? Seems wrong to me... Like it should be the AfterUpdate and not Click

also it sounds like a combobox and not a listbox?
 

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
2,819
It’s a code I’m currently working with.
What you see works fine at present apart from when the values are shown in the listbox the first value is hidden.
I then need to grab the slider to pull down then I see the first value.
If I didn’t know that I would assume that the first entry you see is the first value. But I know the name of the first true value. Any other user would then see the wrong information.
 

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
2,819
Evening,
Please see screenshot.

In The Type Name Box i enter the letter A
All results with the letter A are then shown on the right in the listbox.

As you can see the entry shown at what you think would be the first is A SQUARED 001

Now look on the worksheet behind & you will see the first is actually A BAKALI 001

Grabbing the slider on the right side & pushing it up then brings A BAKALI into view.

So the object of this task is to have the first entry NOT the second entry shown like so.
@jasonb75
 

Attachments

GWteB

Board Regular
Joined
Sep 10, 2010
Messages
170
Office Version
2013
Platform
Windows
It seems that you've a coded connection with a textbox and your listbox. Check the regarding code and consider to insert on the change_event of that control a Me.Repaint to force a repaint of the Userform. That's all I can think of for this moment.
 

Forum statistics

Threads
1,081,641
Messages
5,360,207
Members
400,577
Latest member
crocki

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top