Solved

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

Posted on 2003-11-07
1
223 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
[X]
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
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month7 days, 5 hours left to enroll

622 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