|
-
May 17th, 2000, 04:08 AM
#1
Thread Starter
Addicted Member
How would I get all the information from 1 column in my access database, to show up in a listbox? I was playing around with the "design view" and i saw under the "lookup" tab, that you can use it in a listbox, will someone please inform me here, great thanks!
-
May 17th, 2000, 04:14 AM
#2
Don' use databinding...and use a combo box
Dim db as database
Dim rs as recordset
'
' Set to whatever
'
If not rs.EOF and not rs.BOF Then
rs.MoveFirst
cboText.Clear
Do
cboText.AddItem rs!Whateverfield
rs.Movenext
if rs.EOF Then Exit Do
Loop
cboText.ListIndex = 0
Else
' Whatever error or Message
End If
Hope it helps...am using vb5 sp 3
-
May 17th, 2000, 04:20 AM
#3
Thread Starter
Addicted Member
sorry
sorry, im not familiar with what you were trying to tell me there, im just beginning. All I want to do is transfer all data from a column to a listbox as easly and painlessly as possible, thanks again
-
May 17th, 2000, 04:24 AM
#4
And if you don't actually know the name of the first field you can do
cboText.AddItem rs!Fields(0)
instead of
cboText.AddItem rs!Whateverfield
BTW rs!Fields(0).Name yields the name of the field.
-
May 17th, 2000, 04:27 AM
#5
Hmmmm..........
Ok in my version of vb there is no quick and dirty way of transferring an entire column of data from an access db to a listbox or combobox.
What the code does is
1. Sets the db and rs to the required database and recordset
2. Tests if the recordset has any data in it.
3. Loops through the recordset and adds the individual column items to a combobox.
Not all that difficult.....if you need any help ask specific questions about the code...maybe someone will post a better solution for you:0
-
May 17th, 2000, 04:36 AM
#6
Thread Starter
Addicted Member
what do i do, i have multiple databases on the form
-
May 17th, 2000, 04:58 AM
#7
Ok shouldn't matter
No problems. Each database is going to be uniquely identified and each recordset is opened against a particular database right....
Therefore if you have three database db1 db2 db3
the setting for a recordset is gotta be something like
Set rs to db1.openrecordset(whatever)
Therefore the fact that db2 & db3 are on the same form doesn't affect processing of the recordset in db1.
The same logic no doubt applies to databinding...but it's the first rule in our company's programming guide lines "No use of data binding"...therefore caren't help you with code for that situation.
Hope this helps
-
May 17th, 2000, 06:24 AM
#8
Fanatic Member
Smie!
In Design view of the from, drop a listbox on your form and type in a select statement similar to the one below into the "Rowsource" Property!
"SELECT DISTINCTROW [ProductID],[ProductName] FROM [Products Table];"
Make sure the "RowSource Type = Table/Query"
If you have trouble typing the select statement, put your cursor on the "RowSource" property and click on the elipsee. Make sure your select statement includes the primary key too.
Or another alternative is just selecting the table from "Rowsource" Property and the column you want to "BOUND" property.
Chemically Formulated As:
Dr. Nitro
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
|