|
-
May 1st, 2007, 06:58 PM
#1
Thread Starter
Hyperactive Member
[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
-
May 1st, 2007, 07:56 PM
#2
Fanatic Member
Re: combo box
vb Code:
Dim myStr as string
rs.open " SELECT LETTERS FROM tblInfo", con, adOpenDynamic, adLockOptimistic
If rs.EOF <> True Then
mystr= rs.Fields(0) & rs.Fields(1) & rs.Fields(2)
combobox1.AddItem myStr
End If
rs.Close
-
May 1st, 2007, 09:45 PM
#3
Thread Starter
Hyperactive Member
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
-
May 1st, 2007, 10:12 PM
#4
Fanatic Member
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)
-
May 1st, 2007, 10:32 PM
#5
Thread Starter
Hyperactive Member
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
-
May 1st, 2007, 10:43 PM
#6
Fanatic Member
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
-
May 1st, 2007, 10:56 PM
#7
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|