Full Version: Default word in a combobox...?
UtterAccess Forums > Microsoft® Access > Access Forms
scottye
I have 2 different comboboxes on a form - notice time and highest level of education.
My boss would like them to default to a word "none" rather than having the box blank. I keep telling him this is not a good ideal, however, he wants it and won't let up. Can anyone tell me how (if possible) to do this.

Scottye

Edited by: scottye on Thu May 11 22:00:33 EDT 2006.
Tomolena
It's NOT a good idea. I guess some people just don't like empty spaces. Describe please how these combos are set up.
argeedblu
Hmmm.
That makes it a bad idea?
Glenn
argeedblu
Scottye,
You can use a union query as the row souce for the combo. Unfortunately, you have to create the query in the sql view of the query designed window so you will need to know a little bit of sql (but it's not all that difficult.) Here is a sample.
SELECT fieldname1, fieldname2 FROM tablename UNION SELECT null, "***None***" FROM tablename ORDER BY fieldname2;
Typically, if your want the combo box to store an FK value, fieldname1 will be the pk of the source table and fieldname2 will be the field with the text you want to display in the pick list. Both select clauses must have the same number of fields in the field list.
Glenn
Tomolena
I'm humbled shocked.gif
e's being asked to add complexity for the sake of esthetics. He'll have to add a "NONE" entry to a combo box that has date values in its recordsource. Doable? sure. Desirable? Why?
argeedblu
From the end user's perspective, indicating with the word "none" that there has been no value specified makes the form easier to understand than being left to assume what the blank entry box means. Certainly, doing so does add a small amount of complexity but I believe that forms should be as user friendly as possible.
Glenn
ChrisO
He who pays the piper calls the tune: -
!--c1-->
CODE
Option Explicit
Option Compare Text


Private Sub Form_Current()
  
    [color="green"]' Assuming the Combo Box has a Record Source like: -
  
    ' SELECT EducationLevel
    ' FROM tblHighestLevelOfEducation
    ' UNION SELECT "(None)"
    ' FROM tblHighestLevelOfEducation
    ' ORDER BY EducationLevel;
  
    ' Watch out for no records.[/color]
    Me.cboEducationLevel = Nz(Me.cboEducationLevel.ItemData(0), "(None)")
  
End Sub

Hope that helps the boss.
Regards,
Chris.
Tomolena
Elegant. I stand corrected sir.
scottye
Thanks Glen, Chris, and Tomolena
I am in agreeance with Tomolena. I tried telling him (boss) empty means the same things as seeing the word "none" in the combobox. But, he signs the checks. I think my boss and Glenn think alike. User freindly as possible.
Othank everyone for helping on this one. I would have never figured this out on my own. After work tonight I am going to take a whack at this.
PS - I saw some postings around here somewhere on buying books to learn and VBA and these tricks. Any suggestions? Wait... I do have to mention one thing --- I am one of these people that have A.D.D. I tend to wonder off when reading those large tech manuals.
keys2heaven
I tried this code and it did not work for me. It did display the contents of item.data(0) though.
How would this code be applied for multiple combo boxes on a form? If I had 5 combo boxes that were named cboCategory1 through cboCategory5 and cboItem1 through cboItem5.
ChrisO
If you are getting something displayed from the first row and it is not (None) then there at least three possibilities. (None) is not on the first row or (None) is not one of the displayed columns or (None) is not in the list.
Can you post the Row Source of one of the Combo Boxes?
Regards,
Chris.
scottye
Many thanks everyone for the help.
It took me some time to get this done. But it's working. Now the boss is happy.
Scottye
ChrisO
Well, if I may speak for all others who have helped, you’re welcome.
Is a side note…
Often in printed documents, such as a report, QA requires no entry to be left blank.
This could mean that a blank is not acceptable but ‘(None)’, or a ‘strike through’ or whatever could be acceptable.
The intention is to show that the entry has not been forgotten but is of no consequence.
In this case it’s a form and probably has no bearing on the matter because a form is somewhat of a transient thing.
But when a hard copy is made it can make a difference.
Regards,
Chris.
scottye
Ok... now all of a sudden I am having issues. I thought I had it working…
think I may have unknowingly misled everyone.
In my original post I said I have two combo boxes that need the word “None” as a default – notice time and Education level.
These combos are on the same form but are totally separate from one another.
If Employed, Notice Time Required
(Blank)
None
1 Week
2 Weeks
3 Weeks
Highest Level Of Education or Graduated
(Blank)
General Equivalent Diploma (GED)
High School Diploma
Professional Certificate
Vocational/Technical School
Associate
Bachelor
Master
Doctorate
Other
None
Onoticed Glenn mentioned something about a FK. I don’t have an FK anywhere or for that matter a PK. I didn't think I needed one. I created two tables, Schools and notice time with the above in the tables... created a query, went to the form and created two combo boxes for the user to choose from.
Should I have done this or am I screwing this up? Not allowing me to be able to default to "None".
Scottye
Jack Cowley
ALL tables should have a primary key that is an autonumber data type. Your NoticeTime table should look like this:
blNoticeTime
NoticeTimeID (PK and auto)
AmountOfNotice (Text)
You have the table as the Row Source for a combo box and this combo box is bound to a field in another table and this is where the PK and FK come in. You save the PK from tblNoticeTime to the field (the FK) in the other table, you do NOT save the text '1 Week', for example.
Next is the default value in the combo box. I am assuming that you want the word 'None' to show in the combo box whenever the form is open instead of being blank. Lets assume that None is the first record in the list and its NoticeTimeID is 1. Put the number 1 in the default value of the combo box and it will show None when the form is open and is on a NEW RECORD.
hth,
Jack
scottye
I really confused myself on this one. I have a tendency of doing that.
had a PK in the tblNoticeTime, but not in the tblSchool.
A few changes and it worked nicely.
Thanks Jack!
Jack Cowley
You are welcome! Glad we could help....
ack
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.