Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 375
  • Last Modified:

Set default Combobox value to Select Item...

This may be a simple question but for the life of me I cant get it to work. I have a bound combox and I want the combobox to display "Select Model..." when opening the form or a new record is added. Is there a way to do that without having to add  Select Model... to the table, I tried setting the controls default value property to that but it didn't work. I would like to do it in VBA.
0
skull52
Asked:
skull52
  • 3
  • 3
  • 2
1 Solution
 
Rey Obrero (Capricorn1)Commented:
assuming the row source of your combo is only a single field, use a union query

select "<Select Model..> as field1 from tableX
Union
Select Field1 from tablex

in the load event and new record condition of the form, place

me.comboName.value=me.comboName.itemdata(0)
0
 
PatHartmanCommented:
There is no built in way to do this and I don't recommend adding "Select Model ..." as an option.  And it won't display automatically anyway unless you set it as the default.

If you are using a single record form or a continuous form (this will NOT work on a form in datasheet view), you can try adding a label with a caption of "Select Model ...".  Then on top of the label place the combo.  Set its background to transparent.  The label shouldn't get the focus so it shouldn't interfere with the combo and once something is selected in the combo, it should hide the label.

PS, if you do elect to use Rey's suggestion, you'll need code in the Form's BeforeUpdate event to ensure that the dummy value has been replaced by a valid value because you don't want to actually save a record with that value in it.
0
 
skull52Author Commented:
Rey, it is not it has 2 columns an ID which is actually stored and the model name  which is displayed in the dropdown. I dont mind adding the "Select Model..."  in the table but i am concerned that the user will not select the model and end up storing that value.
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
Rey Obrero (Capricorn1)Commented:
try something like this

select 0, as id "<Select Model..> as field1 from tableX
Union
Select Id, Field1 from tablex
0
 
Rey Obrero (Capricorn1)Commented:
but you need to check in the before update event of the combo if they have selected value other than 0
0
 
skull52Author Commented:
Pat, That seemed to work.
0
 
skull52Author Commented:
Pat the label does interfere with the content of the combo box, but I think I can set the visible property on the label to NO if the Combo Box contains data.
0
 
PatHartmanCommented:
That should work.  I didn't try it and I've never used the technique.  I just leave controls empty.  

You'll need to run the code from the form's Current event and also from the AfterUpdate event of the combo.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now