Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Setting ListIndex with Text Value, without User Interaction...

Posted on 2003-11-07
1
215 Views
Last Modified: 2010-05-03
Here is what im doing. I populate the Combo Boxs with values from a database, which sets the text values and the Itemdata that corresponds to the text value.
Then I retreive values the text values from the database that corresponds to whatever record the user wants to display.

Here is the problem:

When the user finds a record and then edits a record, but just edits one field, the other Combo Boxs remain at a listindex of -1. So when I attempt to UPDATE my database, and retreive the ItemData using - field = cbo.ItemData(cbo.ListIndex). I get an error.
 

Part of Code:

strSQL = "UPDATE tblMaster " & _
            "SET CountyID = " & cboCounty.ItemData(cboCounty.ListIndex) & _
            ", RouteID = " & cboRoute.ItemData(cboRoute.ListIndex) & _
            ", PostMile = " & txtPostMile.Text & _
            ", MaterialID = " & cboMaterial.ItemData(cboMaterial.ListIndex) & _
            ", DetailID = " & cboDetail.ItemData(cboDetail.ListIndex) & _
            ", vDate = " & txtDate.Text & _
            ", Comments = " & txtComments.Text & _
            " WHERE PKey = " & lblPKey.Caption

----

So how would I get the proper listindex through code?
0
Comment
Question by:Drifter88zxtW
1 Comment
 
LVL 28

Accepted Solution

by:
AzraSound earned 125 total points
ID: 9703446
When you initially grab the user data, you need to set the ListIndex property of the combobox after they have been loaded using something like:


For i = 0 to cboCountry.ListCount - 1
    If cboCountry.List(i) = strUsersValue Then
        cboCountry.ListIndex = i
        Exit For
    End If
Next
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to make an ADE file by code? 11 94
MS SQL Update query with connected table data 3 30
Problem to line 23 53
VBA: loop recent folder and copy txt file. 8 33
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

789 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