Results 1 to 9 of 9

Thread: Populating a Listbox with the Contents of a Field from a MDB

  1. #1

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    Smile Populating a Listbox with the Contents of a Field from a MDB

    I need to populate a listbox with the contents of a field in a recordset of a MDB file. When the user clicks on one of the items in the list i need all the textboxes to be populated with thier fields in the same recordset.


    Example: I have 15 textboxes, each one has the info of the 15 fileds in TblLetters. Field1 holds the names of the letters so it is named "Names". Well, i want to populate a listbox with all the "Names" and then when the user clicks on a Name the 15 textboxes are filled with thier coesponding Fields.


    Any help is appreciated.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  2. #2
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    Off the top of me head!

    VB Code:
    1. rs.movefirst
    2.  
    3. Do until rs.eof = true
    4. list1.additem rs.fields("Names")
    5. rs.movenext
    6. Loop

  3. #3
    bindui
    Guest

    Re: Populating a Listbox with the Contents of a Field from a MDB

    Originally posted by Arc
    I need to populate a listbox with the contents of a field in a recordset of a MDB file. When the user clicks on one of the items in the list i need all the textboxes to be populated with thier fields in the same recordset.


    Example: I have 15 textboxes, each one has the info of the 15 fileds in TblLetters. Field1 holds the names of the letters so it is named "Names". Well, i want to populate a listbox with all the "Names" and then when the user clicks on a Name the 15 textboxes are filled with thier coesponding Fields.


    Any help is appreciated.
    Hello.....
    Its so cool cool

    Populate the list as in above reply

    then

    in List1_Click Event write this

    if ur using ADO
    Dim rsDisplayValues As New ADODB.Recordset ''For Displaying the values from table

    rsDisplayValues.Open "Select * from <Tablenmae> " & _
    "Where Name='" & list1.text & "' ", CnAccess, adOpenStatic, adLockOptimistic


    Try and reply

    Itty

  4. #4

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Hi, thanks for the input.

    One problem here. I'm using the Data object and here is my code.

    Data1.Recordset.MoveFirst

    Do Until Data1.Recordset.EOF = True
    List1.AddItem Data1.Recordset.Fields("Names")
    Data1.Recordset.MoveNext
    Loop

    With this code i get the error

    "Object Variable or With Block Variable not set"

    What the heck does that mean?
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  5. #5

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    NM i figured it out thanks. Now on to the next part =)
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  6. #6

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    OK, i thought i was clear sorry if i wasn't.

    I am using the data control from VB. I think you know what i mean.

    I am using an Access MDB Database. I am using the "Microsoft ADO ext. 2.5 for Dll and security" refrence to acces the database.

    I am not sure what other info you need.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  7. #7
    bindui
    Guest
    Can u pls send the sample code that u r working

    It would a great help for me to continue

    Itty

  8. #8

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    There is not any code to show you. I am using a data control it requires almost no code.

    I simply link the data control to the Database MDB then i link the textboxes to the fields.. it's very simple.

    I just need to know how to get the fields to display when i click on the names in a list box.

    Example: I have a list populated with the Items in Field "names". There are 15 fields in this table. When i click on a name in the listbox i want the 15 textboxes to be populated with the items in that field. The textboxes are all conected to the Data1 object which is connected to the recordset/table Names.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  9. #9
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    Using the datacontrol this worked for me!

    VB Code:
    1. Private Sub Command3_Click()
    2. Data1.Recordset.MoveFirst
    3. Do Until Data1.Recordset.EOF = True
    4. List1.AddItem Data1.Recordset.Fields("Names")
    5. Data1.Recordset.MoveNext
    6. Loop
    7. End Sub

    Get rid of the ADO reference you dont need it!
    But dont use datacontrols they really are bad mmmmmm kkkkkk
    B

Posting Permissions

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



Click Here to Expand Forum to Full Width