|
-
Oct 11th, 2001, 02:42 AM
#1
Thread Starter
Junior Member
Combo Box List Items
Hi Guys,
I am new to VB and am having trouble loading a combo box with DB values. Don't have the DBCombo component so am doing it the hard way.
Set myDB = OpenDatabase("c:\Defects\Defects97.mdb")
Set rst = myDB.OpenRecordset("Select * From MajorComponents")
rstc = rst.RecordCount
For rstx = 0 To rstc - 1
Combo1.AddItem rst!MajorComponents & ""
rst.MoveNext
Next
rst.Close
This code almost works. It generates the following error message:
"Object doesn't support this property or method" but still loads some of the records (first 3).
I'd appreciate some help.
Cheers
-
Oct 11th, 2001, 02:46 AM
#2
-= B u g S l a y e r =-
first, the RecordCount prop is not to be trusted 
I always do a movelast movefirst before using the reccount.
maybe the fourth element is empty?
try this:
VB Code:
Set myDB = OpenDatabase("c:\Defects\Defects97.mdb")
Set rst = myDB.OpenRecordset("Select * From MajorComponents")
While Not rst.EOF
Combo1.AddItem rst!MajorComponents & " " 'see the space? :)
rst.MoveNext
Wend
rst.Close
-
Oct 11th, 2001, 02:47 AM
#3
Junior Member
try a while loop? while not EOF u add and movenext so u can give the for loop a miss kind of troublesome sometimes :P
heee i'm new in vb too just a suggestion.
-
Oct 11th, 2001, 03:15 AM
#4
Thread Starter
Junior Member
Combo Box List Items
Fantastic, works like a charm!!
Thanks very much.
-
Oct 11th, 2001, 03:49 AM
#5
-= B u g S l a y e r =-
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
|