Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programmatically select item in DataCombo at runtime

Status
Not open for further replies.

solinox

Programmer
Sep 9, 2003
4
US
I have a set of DataCombo boxes that I'm using to provide a set list of options for the user to select from. The selections are saved, along with other data, in another database table to be retrieved later. I'm using a DataCombo to bind to the table and display the list instead of just loading the list into a regular combo because the list is over 12,000 items long, causing an unacceptable delay in form loading. Using the DataCombo allows the form to load instantaneously.

I create a recordset upon starting the program that open the table containing my list of items, gcsICD. In the Form_Load event of the form in question, I have the following code:

Set dcActive.RowSource = grsList
dcActive.ListField = "Code_Des"
Set dcActive.DataSource = grsList
dcActive.DataField = "CodeID"

When I save my data:

!Code = dcActive.SelectedItem

From looking further I think it's just giving me .AbsolutePosition, not the actual ID field I intended, but it doesn't matter because the ID field is just a counter so the values are the same.

My problem arises on reloading my data for display. I need to be able to set the DataCombo selection on a specific item, based on the ID I pull back up from my database. If I need to reference it as AbsolutePosition of something, I can, because they come to the same thing.

I have tried setting the .AbsolutePosition of my underlying recordset (grsList.AbsolutePosition = !Code), but that doesn't work. I'm not sure how well that would work anyway, because I've got 10 of these DataCombos. If it were a straight ListBox or ComboBox, I could set the .ListIndex and be done with it. I need this DataCombo to allow my forms to load rapidly. How can I reset the DataCombo selection at runtime?

Solinox
 
Hmmm ... not really sure about DataCombo boxes - are they much different to a normal combo box?

For a normal combo box I have a function like this:

Public Sub SetCombo(ByRef cbobox As ComboBox, varItemData As Variant)

On Error GoTo ErrHandler

Dim intCnt As Integer

If IsNull(varItemData) Then
cbobox.ListIndex = -1
Else
For intCnt = 0 To cbobox.ListCount - 1
If cbobox.ItemData(intCnt) = CLng(varItemData) Then
cbobox.ListIndex = intCnt
Exit For
End If
Next intCnt
End If
Exit Sub

ErrHandler:
ErrorHandler err, "modGeneral", "SetCombo"

End Sub

Transcend
[gorgeous]
 
Well, if it's bound correctly, then you should be able to just reposition the underlying recordset:

grsList.Find "CodeID = 123",,, adBookmarkFirst
The dropdown should reflect this as the current item...if found
 
The DataCombo is different from the regular ComboBox. It doesn't even have a ListIndex property to use for repositioning.

I tried repositioning the underlying recordset, but that didn't work for some reason. I do have 10 of these attached to the same recordset, maybe that's why.

I finally gave up and switched to opening an additional lookup form. An extra step for the user that I was hoping to avoid, but at least it works. It seems odd that the DataCombo didn't work, though.
 
>It seems odd that the DataCombo didn't work, though.
But it does. There must be something else overlooked...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top