Getting the recordsets of an access query into a listbox

Discussion in 'AutoCAD' started by eugh, May 19, 2004.

  1. eugh

    eugh Guest

    Hello,

    I have an Access Database with all of our blocks and layernames in two tables, "symbols" and "layernames".

    On a form I have radio buttons for each grouping of block types ie; CHAN, STORM, TOPO. If the user selects the CHAN radiobutton, the listbox is populated by a txt file with only the channelization blocks.

    I'm sure populating the listbox would be better handled by creating a query within the database, then populate the listbox from the query. Correct? If so, I have no idea how to do it. I am using DAO (3.6) for the connection. Please advise.

    Thanks in advance!
    Eugh
     
    eugh, May 19, 2004
    #1
  2. eugh

    eugh Guest

    When I try the code below I get an error # 3251
    "operation is not supported for this type of object."
    What's the problem? FYI "exstwater" is a query, you can acess the reocords of a query the same as a table, correct?


    Private Sub UserForm_Initialize()
    Dim db As database
    Dim RS As Recordset
    Dim Record As Recordset

    'connect to database
    Set db = OpenDatabase("P:\Autodesk\Clientcfg\c-street\Support\DATABASE\c-street.mdb")
    Set RS = db.OpenRecordset("exstwater", dbOpenDynaset)

    RS.MoveFirst
    While Not RS.EOF
    For Each Record In RS.Fields("drawingname")
    ListBox1.AddItem (RS)
    Next
    Wend

    End Sub

    Thanks,
    Eugh
     
    eugh, May 20, 2004
    #2
  3. eugh

    LochDhu Guest

    try changing your loop code to this:

    RS.MoveFirst
    While Not RS.EOF
    ListBox1.AddItem RS.Fields("drawingname")
    RS.MoveNext
    Wend

    Scott
     
    LochDhu, May 20, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.