Results 1 to 3 of 3

Thread: Easier way to db.. err.. do this?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Location
    Atlanta
    Posts
    104
    Say I have a database named test.mdb.
    Inside that database exists a table named Includes which houses only two fields.

    Now, I want to import all of the contents from one of the fields to a list box. To do that I've created something that looks like this:

    Private Sub Form_Load()
    Set DB = OpenDatabase("test.mdb")
    For i = 1 To 9
    Set RS = DB.OpenRecordset("SELECT * FROM _
    Includes WHERE ID = " & i & "", dbOpenDynaset)
    List1.AddItem "" & RS!IncludeTitle, List1.ListCount
    Next i
    RS.Close
    End Sub

    But this seems to only import the first nine (for i = 1 to 9), I know there's an easier way to do it.

    Any suggestions? =).

  2. #2
    Lively Member
    Join Date
    Oct 2000
    Location
    Singapore
    Posts
    98
    try this.

    Set dbs = OpenDatabase("test.mdb")
    Set rst = dbs.OpenRecordset("select * from include")
    While rst.EOF = False
    List1.AddItem rst.Fields("NameOfField").Value
    rst.MoveNext
    Wend

    rst.close
    dbs.close

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Private Sub Command1_Click()
    'Open the database form sub OpenDB
        Call OpenDB
    
    'variables for database and recordset
        Dim dbs As Database, rst As Recordset
    '
    'set the database and recordset
        Set dbs = Workspaces(0).OpenDatabase(cdbName)
        Set rst = dbs.OpenRecordset(ctblName)
    
    'with the recordset do your stuff
        With rst
        While Not .EOF
            List1.AddItem !field1  'list field1
        .MoveNext
            Wend    'loop
            
    'close database and recordset and set them = nothing
        .Close
            dbs.Close
        End With
    
        Set rst = Nothing
        Set dbs = Nothing
        
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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