Solved

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

Posted on 2003-11-07
1
208 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now