473,408 Members | 2,832 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,408 software developers and data experts.

Multicolumn ComboBox

I'm trying to populate a multicolumn combo box with data from a sql query.
First problem is that I have to click the down arrow in the cbox to see the
first record. How do I change that? Second problem is populating each column.
That I can't figure out. Below is the function. As you can see the line that
isn't commented out will get the first column, the second gets the second
column of the record, but both are put in the first column of the combo box.
How do I populate the three columns with corresponding fields and will this
loop through and get all db records specified in the query.

As you can see I commented out some lines that i thought would work, but
don't. I recieve a 424 run-time error, "object required". Would this work if
I solve that problem?

Expand|Select|Wrap|Line Numbers
  1. Public Function AddToCombo()
  2.    Dim dbs As Database, rst As Recordset, strSQL As String, strSQL1 As
  3. String
  4. 'now get the rest of the data from OrderInfo where ordernumber is same
  5. 'and set to variables
  6.    strSQL = ""
  7.    strSQL1 = ""
  8.    Set dbs = CurrentDb
  9.    strSQL1 = "SELECT * FROM OrderData where ordernum = "
  10.    strSQL = strSQL1 & OrderNum
  11.    Set rst = dbs.OpenRecordset(strSQL)
  12.  
  13.    With rst
  14.    i = 0
  15.      Do Until .EOF
  16.      cmbOrders.AddItem .Fields(1).Value
  17.      cmbOrders.AddItem .Fields(2).Value
  18. '      cmbOrders.AddItem (i)
  19. '      cmbOrders.Column(0, i) = .Fields("Quantity")
  20. '      cmbOrders.Column(1, i) = .Fields("Description")
  21. '      cmbOrders.Column(2, i) = .Fields("Price")
  22.      .MoveNext
  23.      i = i + 1
  24.      Loop
  25.      End With
  26.  
  27.    rst.Close
  28. End Function
Jul 30 '11 #1
1 11544
NeoPa
32,556 Expert Mod 16PB
Rod, We only allow one question per thread, but I will quickly deal with the question about how to set the ComboBox to reflect the first record without having to select it manually. The solution is to set the ComboBox value to equal that of the first record. For a MultiColumn ComboBox the value would reflect that column which is the default (or bound) column.

Moving on to your code we find a bit more to deal with. As you have made an attempt though, I will see what I can do about pointing out the mistakes :
  1. In Line #2 Database and Recordset should be defined more specifically as DAO.Database and DAO.Recordset.
  2. Using AddItem is straightforward enough. See below (An excerpt from the Help Page) for how to add rows for MultiColumn controls :
    For multiple-column lists, use semicolons to delimit the strings for each column (for example, "1010;red;large" for a three-column list). If the Item argument contains fewer strings than columns in the control, items will be added starting with the left-most column. If the Item argument contains more strings than columns in the control, the extra strings are ignored.
  3. Context-sensitive help (A page relevant to exactly what you're working on) is easy to use and is a simple keystroke away (Press F1 with the cursor over the word you need help on).
  4. Actually, that long list of problems I noticed all came down to just those two in the end. You have the .MoveNext included already (Frequently overlooked in my experience), so not such a bad attempt after all ;-)

There is another major point here of course though. One that makes most of your code redundant anyway. Why not simply set up the ComboBox as having a Row Source of the query you require. That's actually the normal (and more efficient) way of populating such a control.
Jul 30 '11 #2

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

Similar topics

27
by: DraguVaso | last post by:
Hi, The Multi column comboBox is a well spoken control, that a lot of people desire, and a lot of people buildtheir own. I tested a lot of them, but none really was what i wanted to have. But...
0
by: Keith Smith | last post by:
How can this be done in C#...? http://www.codeguru.com/Cpp/controls/combobox/multicolumncombos/article.php/c1825/
0
by: jaYPee | last post by:
I'm wondering why if there is an example of using a multiplecolumn combobox in datagrid control. thanks in advance
2
by: WStoreyII | last post by:
i would like to display a small three column datagrid in a combobox's drop down list any idea's on how to do this ? WStoreyII
6
by: Lars Netzel | last post by:
I have ask this before and I got a link to a solution where you actually show a new from on top of everything with a listbox in, where you can have multicolumns.. and that's what I use now.. That...
0
by: Lars Netzel | last post by:
It seems like more people than me are looking for something like this.. and I definately see a big benefit having one of these so it's strange to me that noone has made one. Is it possible to...
7
by: Aaron Smith | last post by:
I would like to try to make a combo box have multiple columns. Does anyone know of a good way to attempt this? I saw a project on thecodeproject to do this, I just didn't like the way it looked. I...
5
by: Keith G | last post by:
I am using Visual Studio 2003. In the standard combobox control it would appear that only 1 column of data can be displayed in the list (as stipulated in the DisplayMember property). In VBA it was...
8
by: | last post by:
I am sure this has been asked and answered, but here goes anyway... VS.Net 2005, VB.Net How can you display more than one field in the displaymember property of a combobox inside the...
1
by: vijay dahite | last post by:
can anybody tell me how to write code for multicolumn combobox in vb6.0 plzzzz... vijay
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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...
0
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...

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.