• ADODC and ComboBoxes (VB 6)

    Author
    Topic
    #358584

    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? hairout

    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. nuts

    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.

    Viewing 1 reply thread
    Author
    Replies
    • #535401

      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?

      • #535408

        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.

        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. shrug
          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()

        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.

        • #535425

          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

          • #535468

            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. sick The VB form itself doesn’t really have a recordset, the datacontrol or dataenvironment command object has the recordset.

            • #535569

              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.

    • #535542

      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. grin

    Viewing 1 reply thread
    Reply To: ADODC and ComboBoxes (VB 6)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: