List Box and Combo box 
Author Message
 List Box and Combo box

CAn anybody help me?
I have been trying for days to figure out the proper way to use list boxes
and combo boxes, in VB6
The scenario is that I want to use them in forms to furnish lookup data from
lookup tables, to feed into a master table, to increase data reliability; a
common enough problem.
It seems pretty simple to do this using DBlist andDBcombo controls which
come with VB6, but these seem to need to have their data supplied by a data
control.
Can somebody show me either
 -how to bind the DBList & DBCombo directly to a pair of recordsets, or
- how to bind the listbox & combobox to a pair of recordsets so that I can
feed lookup data from one to the other

Thanks



Thu, 21 Nov 2002 03:00:00 GMT  
 List Box and Combo box

Here is a sample of populating a listbox.

Private Sub Form_Load()

   Dim myDB As Database
   Dim sPath As String
   Dim myRS As Recordset

   sPath = "k:\working\TestCode.mdb"

   Set myDB = OpenDatabase(sPath)
   Set myRS = myDB.OpenRecordset("tnl1")

   Do While Not myRS.EOF
      List1.AddItem myRS(2)
      myRS.MoveNext
   Loop

End Sub

This was using DAO 3.5 and Access 97.  Make sure that the reference to
the DAO 3.5 library is selected in your project references list.

Sol.

Quote:
>CAn anybody help me?
>I have been trying for days to figure out the proper way to use list boxes
>and combo boxes, in VB6
>The scenario is that I want to use them in forms to furnish lookup data from
>lookup tables, to feed into a master table, to increase data reliability; a
>common enough problem.
>It seems pretty simple to do this using DBlist andDBcombo controls which
>come with VB6, but these seem to need to have their data supplied by a data
>control.
>Can somebody show me either
> -how to bind the DBList & DBCombo directly to a pair of recordsets, or
>- how to bind the listbox & combobox to a pair of recordsets so that I can
>feed lookup data from one to the other

>Thanks



Thu, 21 Nov 2002 03:00:00 GMT  
 List Box and Combo box
Thanks for that. I guess I had actually got this far. What I can't now figure out
is how to link the list box filled with lookup data to a field in a main
recordset, so that the list box shows the relevant data as the main recordset is
navigated.
Any help gratefully received

Martin Fugill

Quote:


> Here is a sample of populating a listbox.

> Private Sub Form_Load()

>    Dim myDB As Database
>    Dim sPath As String
>    Dim myRS As Recordset

>    sPath = "k:\working\TestCode.mdb"

>    Set myDB = OpenDatabase(sPath)
>    Set myRS = myDB.OpenRecordset("tnl1")

>    Do While Not myRS.EOF
>       List1.AddItem myRS(2)
>       myRS.MoveNext
>    Loop

> End Sub

> This was using DAO 3.5 and Access 97.  Make sure that the reference to
> the DAO 3.5 library is selected in your project references list.

> Sol.

> >CAn anybody help me?
> >I have been trying for days to figure out the proper way to use list boxes
> >and combo boxes, in VB6
> >The scenario is that I want to use them in forms to furnish lookup data from
> >lookup tables, to feed into a master table, to increase data reliability; a
> >common enough problem.
> >It seems pretty simple to do this using DBlist andDBcombo controls which
> >come with VB6, but these seem to need to have their data supplied by a data
> >control.
> >Can somebody show me either
> > -how to bind the DBList & DBCombo directly to a pair of recordsets, or
> >- how to bind the listbox & combobox to a pair of recordsets so that I can
> >feed lookup data from one to the other

> >Thanks



Fri, 22 Nov 2002 03:00:00 GMT  
 List Box and Combo box


Modify your recordset to select the new data based on the variable
selected.  If I recall there is an ItemSelected or something like that
for the ListBox object (ItemData as I see it)

Private Sub CreateNewList()

    Dim myDB As Database
    Dim sPath As String
    Dim myRS As Recordset
    Dim sWhere as String, sSQL as String
    Dim iCount as Integer

    sPath = "k:\working\TestCode.mdb"

    Set myDB = OpenDatabase(sPath)
    sWhere = List1.ItemData(List1.ListIndex)
    sSQL ="Select * from tnl1 where LookUPField =" & sWhere & ";"
    Set myRS = myDB.OpenRecordset(sSQL)

    Do While Not myRS.EOF
      List1.AddItem myRS(2)
       myRS.MoveNext
    Loop

 End Sub



Wed, 27 Nov 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. dialog box with list box or combo box

2. Limiting Access to Text Boxes, List Boxes and Combo Boxes

3. Updating list boxes and combo boxes

4. HELP! ADO bound list box and combo box

5. List box and Combo box

6. NEEDED:Multi Column Databound List Box or Combo Box

7. help: Implementing a drop down list box or combo box with an unbound text box.

8. How to list macro names in a combo box or a list box

9. Combo box spawning list box

10. Examples of OwnerDrawn for Combo Box / List Box / Menu / Toolbars

11. adding to a combo box or list box

12. pls help : COMBO box or list box

 

 
Powered by phpBB® Forum Software