[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Set default Combobox value to Select Item...

Posted on 2015-02-23
8
Medium Priority
?
372 Views
Last Modified: 2015-02-23
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
Comment
Question by:skull52
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40626436
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
 
LVL 39

Accepted Solution

by:
PatHartman earned 2000 total points
ID: 40626443
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
 

Author Comment

by:skull52
ID: 40626459
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40626510
try something like this

select 0, as id "<Select Model..> as field1 from tableX
Union
Select Id, Field1 from tablex
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40626512
but you need to check in the before update event of the combo if they have selected value other than 0
0
 

Author Comment

by:skull52
ID: 40626517
Pat, That seemed to work.
0
 

Author Comment

by:skull52
ID: 40626906
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
 
LVL 39

Expert Comment

by:PatHartman
ID: 40627010
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

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question