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. adding to a combo box or list box

2. Application Role w/Access 2000 combo boxes, list boxes, reports

3. List box /combo box usage in a DTS VB custom task

4. pls help : COMBO box or list box

5. selecting records for 2nd combo box dependant on first combo box

6. Populate a combo box from another combo box selection

7. Populating a combo box from another combo box

8. Newbie: Set a combo box style(2)/Dropdown list to the first element in the list

9. Updating a combo box list W/limit to list selected

10. Newbie: Set a combo box style(2)/Dropdown list to the first element in the list

11. Adding a Heading for Combo/List box Drop Down list

12. Newbie: Set a combo box style(2)/Dropdown list to the first element in the list


 
Powered by phpBB® Forum Software