Results 1 to 7 of 7

Thread: [RESOLVED] combo box

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Resolved [RESOLVED] combo box

    hello!
    for example i have tblInfo and a field name LETTERS and has values a,b and c
    i used below code but it olny add the "a" value on th combo box
    not the 3 letters

    rs.open " SELECT LETTERS FROM tblInfo", con, adOpenDynamic, adLockOptimistic
    If rs.EOF <> True Then
    combobox1.AddItem rs.Fields(0)
    End If
    rs.Close

  2. #2
    Fanatic Member
    Join Date
    Mar 2002
    Location
    AUSTRALIA
    Posts
    603

    Re: combo box

    vb Code:
    1. Dim myStr as string
    2.  
    3.   rs.open " SELECT LETTERS FROM tblInfo", con, adOpenDynamic, adLockOptimistic
    4.   If rs.EOF <> True Then
    5.     mystr= rs.Fields(0) & rs.Fields(1) & rs.Fields(2)
    6.     combobox1.AddItem myStr
    7.   End If
    8.   rs.Close
    Rob C

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: combo box

    nope...
    i want to add on the combox as dropdown list
    and there is only one(1) field that is "LETTERS"=rs.Fields(0)
    there are no fields(1) and fields(2)

    if you try the first record only will be add to the combo box
    but i want is all the records

  4. #4
    Fanatic Member
    Join Date
    Mar 2002
    Location
    AUSTRALIA
    Posts
    603

    Re: combo box

    Code:
    rs.open " SELECT LETTERS FROM tblInfo", con, adOpenDynamic, adLockOptimistic
    If not(rs.EOF) Then
      rs.movefirst
      do while not(rs.EOF)       
        combobox1.AddItem rs.Fields(0)
        rs.movenext        
      loop        
      rs.Close	
    end if
    That may meet your needs ?
    (I have not tested it)
    Rob C

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: combo box

    tnx rob the problem was solved...
    what's the error here?
    because if the rs is not equal to EOF it must add all the values to combo box.

    rs.open " SELECT LETTERS FROM tblInfo", con, adOpenDynamic, adLockOptimistic
    If rs.EOF <> True Then
    combobox1.AddItem rs.Fields(0)
    End If
    rs.Close

  6. #6
    Fanatic Member
    Join Date
    Mar 2002
    Location
    AUSTRALIA
    Posts
    603

    Re: [RESOLVED] combo box

    If I understand your question 'why did that code not work ?'

    When a rs is in memory, it is like an array, wherein you read the contents of the array by asking for the contents of an element in the array.
    However with a rs there is a pointer to one record.
    You must move that pointer to read the field values in that record
    You only ever get the values of one record at a time.

    You must first position the rs at the first record (which by luck it was on your original code)
    Then after adding the field contents to your combobox (contents of the field in the current record), you must reposition the pointer in the rs to the next record. That is what the movenext does.
    As you move through the rs with movenext, you keep adding the field contents (for the current record) into the combobox
    Last edited by RobCrombie; May 1st, 2007 at 10:46 PM.
    Rob C

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: [RESOLVED] combo box

    ok tnx for your explanation
    i thought it will keep adding to the combobox until it reaches the .EOF
    even without loop and moving...

    tnx again.

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