Results 1 to 7 of 7
  1. #1
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    ADODC and ComboBoxes (VB 6)

    Has anyone found an easy (relatively, that is) way to set the index in an unbound combobox based on the value in a bound textbox using a form bound to an ADO data control? <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>

    I finally figured out that I couldn't reference a bound control on the form and had to reference the ADODC's recordset!field instead, but I'm curious as to whether anyone else has found a better way. Event after the MoveComplete event of the ADODC, referencing the bound textbox gives me the value that was in it in the previous record referenced, not the value seen on the screen. <img src=/S/nuts.gif border=0 alt=nuts width=15 height=15>

    I don't want keys to show in the combobox, only their lookup values, so I can't just bind the thing. I found a workaround, but there must be an easier way.
    Charlotte

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ADODC and ComboBoxes (VB 6)

    Hate to leave you stranded on this. Can you be a bit clearer? How about some code to look at.

    I always read recordset rows into a multi-dim array, assign the array to the combo control and indicate bound column and textcolumn to suit the form. Instead of trying to set the index to display the value you want, set the .Text property to the value in the bound textbox.

    Does that help?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: ADODC and ComboBoxes (VB 6)

    You must be looking at a different kind of combobox than the standard vanilla one that comes with VB 6. Those don't have a bound column property that I've found and they only allow a single column. There is a combobox for use with the DataControl that has more properties, but you can't use it with the ADO DataControl. Is that the one you're talking about or are you using still another one?

    Since the rows in the combobox are names of things and the values in the textbox are long integer IDs, I don't see any way to do what you suggest.

    As far as the code goes, here's what I'm using now.<pre>Private Sub SetComboPointer()
    Dim intIndx As Integer 'holds the index for the array
    Dim lngRegion As Long 'holds region from recordset

    On Error GoTo Proc_err

    'store the region value from the current record
    'in the datacontrol's recordset
    'Note: you don't get the correct value if you
    ' reference the textbox, you get the previous
    ' value instead. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    lngRegion = adcOutgrant.Recordset!Region

    'loop through the array to find a match for the region
    For intIndx = 0 To UBound(mudtRegions)
    If mudtRegions(intIndx).RegID = lngRegion Then

    'use the secondary index to set the listindex
    cboRegion.ListIndex = cboRegion.ItemData(intIndx)
    Exit For
    End If 'mudtRegions(intIndx).RegID = adcOutgrant.Recordset!Region
    Next intIndx '= 0 To UBound(mudtRegions)

    Proc_exit:
    Exit Sub
    Proc_err:
    If Err = 9 Then
    Resume Proc_exit
    Else
    MsgBox Err.Number & "--" & Err.Description
    End If
    Resume Proc_exit
    End Sub ' SetComboPointer()</pre>


    mudtRegions is an array of a user-defined type that I also use to lookup the RegionID when a choice is made in the combobox so I can insert the value into a textbox. The items in the array are indexed the same as the secondary index (itemdata) of the combobox.
    Charlotte

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: ADODC and ComboBoxes (VB 6)

    I don't have VB6, but the combobox in Office 2000, supposedly close kin to VB6, allows multiple columns as in Access 2000.

    Uh, I may have just run out of even marginally useful things to say. What I myself have done in the past, in abbreviated form, is:

    UserForm.Show
    RecordSet.MoveFirst
    RecordSet.Move UserForm.ListBox1.ListIndex

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: ADODC and ComboBoxes (VB 6)

    VB is blessed with a variety of comboboxes and their properties are somewhat different from those available from the Office apps. VB is essentially geared toward unbound forms, but when you bind a form to a dataenvironment directly or through a datacontrol, you still have to wrestle with the particular kind of comboboxes designed to work with that datacontrol. <img src=/S/sick.gif border=0 alt=sick width=15 height=15> The VB form itself doesn't really have a recordset, the datacontrol or dataenvironment command object has the recordset.
    Charlotte

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: ADODC and ComboBoxes (VB 6)

    Never mind, guys. I finally figured out the problem with the bound comboboxes--I had the DataBound List component checked instead of the DataControls. The little icons for the controls look the same except for the color, so I missed it. Now I can abandon trying to code around the problem and just use the built-in capabilities. Of course, if anyone knows how to *filter* one of those DataCombo controls based on a selection in another one, I'd be delighted to save myself some work. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Charlotte

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: ADODC and ComboBoxes (VB 6)

    Oh, sorry, I was rather vague. The RecordSet is defined in the subprocedure, and when the user dismisses the UserForm, it returns the ListIndex so that I can scroll through the RecordSet to the matching record. Someday I'll learn your method: sounds as though it might be more efficient.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •