Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

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 …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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

877 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