Automatically have first drop down item selected

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. Windows
Hi,
I have a database of which is a userform and i select my info to appear from making a selection from within a drop down box.
Currently when the form opens its fields are blank & i am having to select from drop down box so the fields now have data & then i can use the up/down arrows on keyboard to navigate the info in the list.

I would like for the form to open & the first available item in the list to be automatically selected,so i can then just start to navigate.
Thanks.

This list is longer than below but gives you the idea of it.

Code:
Private Sub TextBox10_Change()

If Me.TextBox10.Value = "FO 21" Then
Image1.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\FO21.jpg")
Image2.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\2FO21.jpg")


ElseIf Me.TextBox10.Value = "HON 41" Then
Image1.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\dr-logo.jpg")
Image2.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\2HON41.jpg")


ElseIf Me.TextBox10.Value = "HON 58" Then
Image1.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\HON58.jpg")
Image2.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\2HON58.jpg")


ElseIf Me.TextBox10.Value = "HON 59" Then
Image1.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\HON59.jpg")
Image2.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\2HON59.jpg")


ElseIf Me.TextBox10.Value = "HON 66" Then
Image1.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\HON66.jpg")
Image2.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\2HON66.jpg")


ElseIf Me.TextBox10.Value = "HON 70" Then
Image1.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\HON70.jpg")
Image2.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\2HON70.jpg")


ElseIf Me.TextBox10.Value = "HON 77" Then
Image1.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\HON77.jpg")
Image2.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\2HON77.jpg")

End If
End Sub
 
With this code shown below and in use,
Code:
Private Sub UserForm_Initialize()ComboBox1.Value = "FO 21"
ComboBox1.SetFocus
End Sub

When the form is open i just see a vertical line after the FO 21
I then try to use the arrows on the keyboard but nothing happens.

 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
This is what i see when form is open.

3998.jpg
excel22.jpg
 
Upvote 0
Any chance of sharing your workbook on google drive or some similar sharing site?

I can't imagine why you can't scroll through the list with the arrow keys....
 
Upvote 0
AHAAA :) ....ok, you were loading the combobox list after someone clicked the drop button. SO when the form first opened, it wouldn't scroll through the list because there was no list. It made the value "FO 21" and made it LOOK like it had picked the first line of the list.

I moved the dropbutton_click event you had into the initialize event, and it worked....so try this...all in the initialize code, delete the dropbutton_click code.

Code:
Private Sub UserForm_Initialize()
Dim i As Long, LastRow As Long
LastRow = Sheets("INFO").Range("BC" & Rows.Count).End(xlUp).Row
If Me.ComboBox1.ListCount = 0 Then
For i = 2 To LastRow
Me.ComboBox1.AddItem Sheets("INFO").Cells(i, "BC").Value
Next i
End If
ComboBox1.Value = "FO 21"
ComboBox1.SetFocus
End Sub

BTW, that is a HUGE userform lol. I had to move the combobox WAY left just so I could see it on my meager little monitor without dragging the UF over (and possibly messing up the focus on the combobox in the process) lol.
 
Last edited:
Upvote 0
Perfect.
Works well now.

Many thanks for the continued effort.

Have a nice day.
 
Upvote 0
I was also checking out some of the other coding, if you're interested, I THINK...THINK...this will do the same as your textbox10_Change event code...I THINK. I couldn't test it, because I don't have all your pictures...I msgbox'ed the file name and it looked right, but PLEASEEEEE test this on a copy of your workbook before putting it in the real thing. I can't stress this enough :) ....on a copy...please.

Code:
Private Sub TextBox10_Change()

Select Case TextBox10.Value
    Case "HON 41", "LEXUS TOY 48", "TOYOTA TOY 43", "TOYOTA TOY 48", "SUZUKI TOY 43"
        GoTo SpecialCase
    Case Else
        Image1.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\" & Left(TextBox10.Value, InStr(1, TextBox10.Value, " ") - 1) & Right(TextBox10.Value, InStr(1, TextBox10.Value, " ") + 1) & ".jpg")
        Image2.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\2" & Left(TextBox10.Value, InStr(1, TextBox10.Value, " ") - 1) & Right(TextBox10.Value, InStr(1, TextBox10.Value, " ") + 1) & ".jpg")
        Exit Sub
End Select
    
SpecialCase:
Select Case TextBox10.Value
    Case "HON 41"
        Image1.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\dr-logo.jpg")
        Image2.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\2HON41.jpg")

    Case "LEXUS TOY 48"
        Image1.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\dr-logo.jpg")
        Image2.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\AWAITINGIMAGE.jpg")

    Case "SUZUKI TOY 43"
        Image1.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\TOY43.jpg")
        Image2.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\2SUZTOY43.jpg")

    Case "TOYOTA TOY 43"
        Image1.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\dr-logo.jpg")
        Image2.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\2TOYTOY43.jpg")

    Case "TOYOTA TOY 48"
        Image1.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\dr-logo.jpg")
        Image2.Picture = LoadPicture("C:\Users\Ian\Desktop\REMOTES ETC\LOCK PICKING IMAGES\2TOYTOY48.jpg")
End Select

End Sub

And make sure it does what you expect and shows the pictures you expect on ALL the values in your combobox list.

If you don't want to mess with it, I understand...I was just piddling around anyway :)
 
Last edited:
Upvote 0
Hi,

i will check it out now on a copy.

Tell me what is the difference in its operation or did you just clean it up ?
 
Upvote 0
No difference really, just not so many IF statements (none actually...changes to Case statements). Even with the number of IFs you had, I seriously doubt this will make any time difference...nano-seconds maybe lol. So, like I said, if you don't want to mess with it, I wouldn't blame you at all.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top