Results 1 to 5 of 5

Thread: Combo Box List Items

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2001
    Location
    Brisbane, Australia
    Posts
    17

    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

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    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:
    1. Set myDB = OpenDatabase("c:\Defects\Defects97.mdb")
    2. Set rst = myDB.OpenRecordset("Select * From MajorComponents")
    3.  
    4. While Not rst.EOF
    5.      Combo1.AddItem rst!MajorComponents & " "  'see the space? :)
    6.      rst.MoveNext
    7. Wend
    8. rst.Close
    -= a peet post =-

  3. #3
    Junior Member
    Join Date
    Sep 2001
    Posts
    21
    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.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2001
    Location
    Brisbane, Australia
    Posts
    17

    Combo Box List Items

    Fantastic, works like a charm!!

    Thanks very much.

  5. #5
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    -= a peet post =-

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