Results 1 to 6 of 6

Thread: Select info from DB to Listbox using DAO

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    norcross, ga, USA
    Posts
    82

    Post

    SQL like:

    SELECT app_title AS variable WHERE Cd_Title = cboCdTitle.Text

    Then add every thing that matches and add it to a list box.

    Unfortunately, it only adds the very first apptitle, many times?!

    ---->CODE CUT<----
    Set db = OpenDatabase("E:\projects\CD DB\db1.mdb")

    SQLString = "SELECT COUNT(App_Name) As count FROM sheet1 WHERE Cd_Title='" & cboCdTitle.Text & "'"

    Set rs = db.OpenRecordset(SQLString)
    count = rs.Fields("count")

    SQLString = "SELECT App_Name As apptitle FROM sheet1 WHERE Cd_Title='" & cboCdTitle.Text & "'"
    Set rs = db.OpenRecordset(SQLString)
    appname = rs.Fields("apptitle")

    For I = 1 To count
    lstApp.AddItem appname
    Next I

    --->END CODE CUT<---

    Thanks in advance!

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Do this instead. You don't need to do any SQL to get the count.
    =======================================
    Set db = OpenDatabase("E:\projects\CD DB\db1.mdb")

    SQLString = "SELECT App_Name As apptitle FROM sheet1 WHERE Cd_Title='" & cboCdTitle.Text & "'"
    Set rs = db.OpenRecordset(SQLString)
    appname = rs.Fields("apptitle")

    Do Until rs.EOF
    lstApp.AddItem rs!appname ' If this gives an error then change "!" to "."
    rs.MoveNext
    Loop

    ------------------
    Marty
    Can you buy an entire chess set in a pawn shop?


    [This message has been edited by MartinLiss (edited 01-22-2000).]

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    norcross, ga, USA
    Posts
    82

    Post

    Thanks for your help guys, but Marty...even if I change the exclamation to a period it still says item not found in this collection!

    I tried rs!appname, rs.appname, and
    rs![appname]. But unfortunately, it only gives me any return to the listbox when I use just 'appname' by itself.

    Unfortunately same problem.

  4. #4
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    try rs.Fields(0).value

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    norcross, ga, USA
    Posts
    82

    Post

    That did it...Turns out I was unable to get online...so I fiddled with it and got it to work....

    I used....

    rs.Fields("apptitle")

    Thanks for everyone's help!


  6. #6
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    If you have multiple records with the same name, you can use:
    SELECT DISTINCTROW App_Name....

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