Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-11-07
1
Medium Priority
?
229 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 500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…
Suggested Courses

722 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