Default value in a combo box

D

Dan

I have a form with a combo box listing a series of values. Instead of a
NotInList routine, I would like to have a default value appear in the combo
box when a new form is opened so that the user can tab to the combo box and
either accept the default value or pull down the list to select a different
value. Any help appreciated.
Thanks,
Dan
 
K

Ken Snell [MVP]

You'll need to run code that sets the combo box value to the desired value.
If you want this to occur when the form opens, you could use the form's Load
event to do this. In the example below, I'm setting the combo box to the
first item in its list:

Private Sub Form_Load()
Me.ComboBoxName.Value = Me.ComboBox.ItemData(0)
End Sub
 
D

Dan

Ken:
I tried:
Private Sub Form_Load()
Me.SourceID.Value = Me.SourceID.ItemData(0)
End Sub

Doesn't work. Data is in table tblSource with 2 fields: SourceID and Source.
Combo looks at this table. Did I misinterpret your suggestion?
Thanks,
Dan
 
K

Ken Snell [MVP]

Is SourceID the name of the combo box? It shouldn't be, but if it is, use
this:

Me!SourceID.Value = Me!SourceID.ItemData(0)
 
J

jwh

What if you were not using user forms but a standard combo box. I have a
combo box that puts the value of the "list" in a cell that the cursor was in
when I double click it. But I would like to have a default value - any
suggestions.
 
K

Ken Snell [MVP]

Combo boxes are used on a form... so I'm confused by your description of
"not using user forms but in a standard combo box"?

More information, please.
--

Ken Snell
<MS ACCESS MVP>
 
J

jwh

Sorry, I am probably goofing up but I use a combo box from the control
toolbar on my normal spreadsheet -- no forms at all. I had to use this type
of box because of my double click thing and my active cell. I have since put
a default of "" in the drop down list. Should I be concerned about not using
the right box?
 
K

Ken Snell [MVP]

Now I am sure I'm confused... ACCESS does not have spreadsheets. Are you
working in EXCEL or ACCESS?
 
J

jwh

Ken,
I am sorry to have wasted your time. When I did the search I did not just
search the excel forum but all forums and never looked until you posed this
question. I promise I do have an IQ and I am intelligent -- apparently I
need more sleep - smile. Thanks for your time and sorry to have confused
you. :)
 
T

TKM

Ken,

This code works but it defaulted all of the past records to Pending also. I
was looking for the same thing so I am not the orignal poster. How do I get
all the original fields bck to the way they were and have a defualt set?
 
Top