473,765 Members | 2,121 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Populate combo box with only unique values

8 New Member
Hello,

I am trying to populate a combo box with only unique values. Currently I am using an access database and VB6 Enterprise. The program populates the combo box fine however, there are several repeated values in this column. What i would like to do is just show one instance of that particular record.

For example:

if the column has the values: Accounts Payable, Process Control, Shipping, Accounts Payable

i would like the combo box just to list: Accounts Payable, Process Control, Shipping


I have tried several attempts and comparing each record set as they are listed, but that seems to throw me into an infinite loop and the program will crash. Eventually i would like it to work as follows, however if there is another way I am open for suggestions.

While Not rs.EOF
if rs!Column_Name <> "" Then
strData = rs!Column_Name (strData is a string)
Call CheckRepeat (will return a boolean Unique)
if Unique = True Then
Combo1.Additem (strData)
end if
rs.MoveNext
end if
wend

Thanks!!
Nov 2 '06 #1
5 11696
sashi
1,754 Recognized Expert Top Contributor
Hi there,

Use the DISTINCT keyword, all you need is a little SQL knowledge. Take a look at below sample code segment. Good luck & take care.

Expand|Select|Wrap|Line Numbers
  1.   Select DISTINCT fldName from tblName
  2.  
Hello,

I am trying to populate a combo box with only unique values. Currently I am using an access database and VB6 Enterprise. The program populates the combo box fine however, there are several repeated values in this column. What i would like to do is just show one instance of that particular record.

For example:

if the column has the values: Accounts Payable, Process Control, Shipping, Accounts Payable

i would like the combo box just to list: Accounts Payable, Process Control, Shipping


I have tried several attempts and comparing each record set as they are listed, but that seems to throw me into an infinite loop and the program will crash. Eventually i would like it to work as follows, however if there is another way I am open for suggestions.

While Not rs.EOF
if rs!Column_Name <> "" Then
strData = rs!Column_Name (strData is a string)
Call CheckRepeat (will return a boolean Unique)
if Unique = True Then
Combo1.Additem (strData)
end if
rs.MoveNext
end if
wend

Thanks!!
Nov 2 '06 #2
albertw
267 Contributor
hi
or use 'plain' VB

put

Expand|Select|Wrap|Line Numbers
  1. Public Const CB_FINDSTRING = &H14C
  2. Public Const CB_FINDSTRINGEXACT = &H158
  3.  
  4. Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  5.  
in your general declaration

and use

Expand|Select|Wrap|Line Numbers
  1. Ret = SendMessage(cboComboBox.hwnd, CB_FINDSTRINGEXACT, -1, strCompare)
  2. if Ret=-1 then cboComboBox.AddItem strCompare
  3.  
where Ret is your ComboBox listindex
and strCompare is the string your are looking for in your ComboBox.

if you get an error-message regarding the called API
change to lParam As String
Nov 2 '06 #3
Killer42
8,435 Recognized Expert Expert
... if you get an error-message regarding the called API change to lParam As String
It's been quite a while, but don't you need to define string parms for API calls as ByVal to make VB pass them as null-terminated format?
Nov 2 '06 #4
willakawill
1,646 Top Contributor
Interesting couple of answers.

Sashi gets it handled before it happens while the other is an extremely involved fix after the fact. I would go with DISTINCT every time :)
Nov 2 '06 #5
Killer42
8,435 Recognized Expert Expert
Interesting couple of answers.
Sashi gets it handled before it happens while the other is an extremely involved fix after the fact. I would go with DISTINCT every time :)
Depends where the info is coming from, of course.
If you can source just the unique values in the first place, that is obviously preferable to filtering them as you populate the control, however the filtering is done.
Nov 2 '06 #6

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

Similar topics

2
5472
by: Sean | last post by:
Greetings all, I am attempting to make a form that will filter through several tables that (I believe) have refretial integrity. I am pulling data from several tables into the form and i would like to eventually be able to filter down through the tables untill i can reach one unique record. I am creating a datbase to keep track of registered accounts for a stae program. Each account is registered into the program through a two...
4
12848
by: godber | last post by:
I need to populate text boxes for instance with employee information using their unique employee works number selected from a combo box. Can anyone help, I am told thru visual basic this can be achieved.
1
2039
by: Cindi | last post by:
Hi, Another newbie with a question that I hope someone can point me in the right direction. The goal is to populate a text box with data according to the selection in a combo box while still being able to navigate the records one by one. The combo box record source is a table/query asking for the ID, Subj, Title, CourseGoals from one table and displays Column 1. I've set up the text box
11
12312
by: DSR | last post by:
Help Please... I would like to populate a combo box on a form with a query that compares data from two tables. Any record that is unique in table1 should continue to populate my combobox. The instant the record appears also in table2 it should no longer be listed in my combo box. This is not a key field in either of the tables. Basically what I am trying to do is prevent the user from entering duplicate values even though it is not a key...
1
6002
by: freekedoutfish | last post by:
Hi. New member here Im sat at work, pounding my head off the desk because this tiny bit of simple code refuses to work. The sub is intended to pull data from the "companyname" column in the "cmSelectAllCompanyNames" table, and put all the company names it finds into the "cbFilterCompanyName" combo box. Now the confusing aspect is this: It works!!!
11
2690
by: martin DH | last post by:
I have an Access database of employees. Each employee has a unique identification number called "BANNER_ID". Each employee's last name and first name are in the database but are not unique (obviously). The data is stored in a table named EMPLOYEE. I want to create a search option whereby managers can search for an employee by "BANNER_ID" by entering the number and pressing a command button named "Search". I want to create an...
2
2613
by: CrazyAL | last post by:
I am working on a form to add entries into my assets table. I am trying to figure out how to make a purchase price field auto populate after entering model number into a combo box. There maybe a much simpler way to do this but here is what I have: Private Sub Combo_Model_Exit(Cancel As Integer) Dim varPrice As Variant varPrice = DLookup("PurchasePrice", "tblModelInfo", "ModelNumber = ") If (Not IsNull(varPrice)) Then Me! =...
4
13971
by: whamo | last post by:
I have the need to populate a field based on the selection in a combo box. Starting out simple. (2) tables tbl_OSE_Info and tbl_Input; tbl_OSE_Info has three fields: Key, OSE_Name and OSE_Wt tbl_Input has three fields: OSE_Job, OSE_Name, OSE_Wt I have populated tbl_OSE_Info table. I need to create a form that will store the data in tbl_Input I have racked my brain so much trying to figure out how to auto populate a field based on a...
2
3324
by: Ronald | last post by:
I hope somebody can help. I can't get into the specifics of my project, but I'll try to create a simple example: tblVehicle * VIN (text box) * Make (text box) * Model (text box) frmRepair
0
9398
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.