Automatically have first drop down item selected

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
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
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
If the box in question is textbox10, you could just type something into it in the VB Editor, and when it opens it will have that value in it.

Works the same with a combobox if that's what you're using, which I suspect is the case since you said "drop down box".

Or you could enter something into either one on the Userform_Initialize event.

If you type it in manually, it wont trigger the Change event, so you'll have to find another way to run the above code.
 
Upvote 0
I have the following now which when the form opens the first entry in the combobox is now shown.
The next part of which i cant get my head around is having the entry selected / highlighted etc so i can just use the arrows on keyboard.

Code:
Private Sub UserForm_Initialize()
ComboBox1.Value = "FO 21"
End Sub
 
Last edited:
Upvote 0
Hi,
I did try that of which it does put a cursor in the text box in question but doesnt high light it so using the arrows has no affect.

I cant believe how hard this is being for such a simple request
 
Upvote 0
Ok...just so I'm sure we're talking about the same things....this is a combobox?....or textbox?...or are you using both and need the textbox to do something also?

If I create a combobox and add a few list items...add a textbox and set is as tabstop 1 , so on initialize, it's got focus (until I tell it otherwise)...Then add your code above and "Combobox1.SetFocus", it sets the value to the first list item, and I can use the arrow keys to go through the rest of the list. it doesn't drop the list down, but I can go through it....
 
Last edited:
Upvote 0
Yes its a ComboBox.
If i click in it when the userform is open i see the items as,
FO 21
HU 66
HON 66
SZ 11

etc etc

When i open the form i am currently clicking in this box & making a selection.
Hence this post,i need to open the form and the first entry is selected of which is FO 21 and all the text boxes are also filled.
I can then use my arrows to scroll through the list.
 
Upvote 0
What you do with the Change event should be the same as before. What you're wanting different than, say, 2 hours ago is to set the focus to the combobox and "select" (or show) the first item in your list...right?

I'm assuming you're using a combobox_Change event to make the textboxes do whatever you want them to do. Is that right? If so, that wont be affected...a change event is a change event, no matter how you make it change.
 
Upvote 0
So if the post above is all correct, this:

Code:
Private Sub UserForm_Initialize()
ComboBox1.Value = "FO 21"
ComboBox1.SetFocus
End Sub

Should do what you're wanting to do. It did for me when I tested it.
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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