|
-
Oct 21st, 2000, 11:14 PM
#1
Thread Starter
Lively Member
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? =).
-
Oct 22nd, 2000, 01:13 AM
#2
Lively Member
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
-
Oct 22nd, 2000, 08:53 AM
#3
_______
<?>
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|