[Webinar] Streamline your web hosting managementRegister Today


Problem with AddItem

Posted on 2008-02-07
Medium Priority
Last Modified: 2012-05-05

I'm attempting something that should be very simple, but is turning out not to be.  Here's the line that works:

            cboSolutions.AddItem rsCase("Solution_Description")

where "Solution_Description" is a large string.  cboSolutions. is a standard combo box.

I've decided I want to add the ID in to the index field of the combo with each string entry, so I tried:

             cboSolutions.AddItem rsCase("Solution_Description"), rsCase("Solution_ID")

where "Solution_ID" is an integer.  It didn't like this at all.  I expermented by putting a straight integer in the second field, and by putting a string literal in the first field after that.

What am I missing?
Question by:NigelRocks
  • 3
LVL 77

Expert Comment

ID: 20842679
Use ItemData property:

cboSolutions.AddItem rsCase("Solution_Description")
cboSolutions.ItemData(NewIndex) = rsCase("Solution_ID")
LVL 77

Expert Comment

ID: 20842728
The second parameter specifies an existing position in the list, so must not equal or exceed the number of items.

Author Comment

ID: 20845161
Where do you get the "NewIndex" variable?
LVL 77

Accepted Solution

GrahamSkan earned 1000 total points
ID: 20845419
Sorry. Failed to test. It's a property of the combo control, meaning the index of the last item added.
cboSolutions.AddItem rsCase("Solution_Description")
cboSolutions.ItemData(cboSolutions.NewIndex) = rsCase("Solution_ID")

Open in new window


Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

590 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