473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Adding a Value to the top of a combo box

mshmyob
904 Expert 512MB
Ok need a litle help on this one guys.

I have a combo box that displays value from a Category table and the selected value will be stored in my Contact table.

No problem there that part works fine.

What I would like to do is display a value called "Not Assigned" at the top of the combo box all the time. The value of "Not Assigned" is NOT stored in the Category table. I am trying to accomplish this without storing "Not Assigned" in the Category table.

If this can be done the value of CategoryID should be assigned the number 0 and stored in the Contact table.

Category table as 3 fields

CategoryID - Autonumber - PK
CategoryDesc - Text - ie: Client, Vendor, etc.
CategoryColour - Text - used to store a hex number

CategoryID is the FK in my Contact table

The combo box currently has the following properties:

Control Source - CategoryID

Row Source - SELECT [tContactCategory].[CategoryID], [tContactCategory]. [CategoryDesc] FROM tContactCategory ORDER BY [CategoryDesc];

Bound Column - 1
Column Count - 2
Column Widths - 0,1


Any ideas?

cheers,
Jun 26 '08 #1
6 1361
ADezii
8,834 Expert 8TB
Just subscribing, will check in later.
Jun 27 '08 #2
ADezii
8,834 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1. 'To display Not Assigned (leading Space)
  2. SELECT tContactCategory.CategoryID, tContactCategory.CategoryDESC
  3. FROM tContactCategory
  4. UNION
  5. SELECT '0', ' Not Assigned'
  6. FROM tContactCategory
  7. ORDER BY tContactCategory.CategoryDESC;
Expand|Select|Wrap|Line Numbers
  1. 'To display (Not Assigned) 
  2. SELECT tContactCategory.CategoryID, tContactCategory.CategoryDESC
  3. FROM tContactCategory
  4. UNION
  5. SELECT '0', '(Not Assigned)'
  6. FROM tContactCategory
  7. ORDER BY tContactCategory.CategoryDESC;
Jun 27 '08 #3
NeoPa
32,556 Expert Mod 16PB
Try this. It brings in just one line to add to the results from [tContactCategory].
Expand|Select|Wrap|Line Numbers
  1. SELECT [CategoryID],[CategoryDesc]
  2. FROM tContactCategory
  3. UNION SELECT Max(0),Max('Not Assigned')
  4. FROM tContactCategory
  5. ORDER BY [CategoryDesc]
Let us know how you get on with these :)
Jun 27 '08 #4
mshmyob
904 Expert 512MB
Thanks guys I won't be able to try it until about Wednesday. This personal project has to be put on the back burner for paying projects (lol). I'll let you know.

cheers,
Jun 29 '08 #5
mshmyob
904 Expert 512MB
Thanks guys. I got a few minutes tonight to look at it.

Dezi your way was the way I tried originally but I reversed my Union query and it didn't work. Your way worked so I assumed I was originally on the right track and I made a slight change to your suggestion to allow any value in the CategoryDescription and not have to worry about putting leading spaces or brackets to force it on top. I created a new orderby (See below) that takes care of the ordering and is more flexible.

Neo I couldn't get yours to work but I haven't had much time to examine it. I will look around Wednesday when I get more time to analyse it.

Thanks guys.

Expand|Select|Wrap|Line Numbers
  1. SELECT tContactCategory.CategoryID, tContactCategory.CategoryDESC, 1 AS SortOrder FROM tContactCategory UNION Select '0' AS CategoryID, 'Not Assigned' AS CategoryDesc, 0 FROM tContactCategory ORDER BY  SortOrder, tContactCategory.CategoryDESC;
  2.  
cheers,
Jun 30 '08 #6
NeoPa
32,556 Expert Mod 16PB
I missed that you needed it at the top :( Is that what you meant when you said you couldn't get it to work?

Try this anyway and let me know :
Expand|Select|Wrap|Line Numbers
  1. SELECT [CategoryID],[CategoryDesc],1 AS [CatSort]
  2. FROM tContactCategory
  3. UNION SELECT Max(0),Max('Not Assigned'),Max(0)
  4. FROM tContactCategory
  5. ORDER BY [CatSort],[CategoryDesc]
You may have to adjust the ComboBox to allow for, but not show, the third column ([CatSort]), or even reorder the columns as you see fit.
Jun 30 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Reggie | last post by:
Hi and TIA! I have a bound combobox with rowsource set to value list, limit to list=true and NotInList procedure to add(or not) a value the user types in. This works fine and it does add the...
3
by: MS | last post by:
What's the best way to "store" and display a value in a text box that changes from day to day. An example of this would be where the name of the user is manually typed in after using the datbase,...
1
by: Dave | last post by:
I have a problem which I know there is an answer to but have so far been unsuccessful in finding it. It is quite simple in theory. I have created a form which uses a table for lookup values and...
3
by: ILCSP | last post by:
Heello, I'm using Access 2000. I have a form with a combo box that has a query as its row source and it's bound to column 1. This combo box is unbound to a record like the rest of the form...
4
by: Gav | last post by:
I am using VS 2005 and am trying to add items to a combo box using C#. I know how to add simple text items but I am trying to add a value and some text ie. Value Text A First Text B ...
5
by: Aaron Ackerman | last post by:
I have a bound combobox the appears on a cell within the column of my bound grid when the user clicks on a cell n(In my vb.net WinForm app). I am trying to allow the adding of an item to that bound...
6
by: vb | last post by:
Hi, I am new to .Net. I am using a Combo Box in my windows forms. I am adding the items by creating the instances and adding the same to the list. My questions/doubts are: 1. If I have 25 to...
1
by: Shawn Yates | last post by:
It has been a while since I have done anything on MS Access and I seem to be a bit rusty. I hope someone could help me solve my issue. I have a form that has multiple combo boxes on it. Each box...
1
by: The Eclectic Electric | last post by:
I'd be very grateful if anyone could help me with this. From my limited knowledge of Javascript I don't think it is possible, but I'll punt anyway. I downloaded and very slightly adapted this...
3
by: =?Utf-8?B?Y2RtdW5veg==?= | last post by:
I have created a sub routine to programmatically add an indefinite number of combo boxes to a form. The combo boxes are bound in code to a view for displaying the available options. This routine...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.