Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Combo Box list from DB

0 views
Skip to first unread message

Marcus Booth

unread,
Jul 11, 2000, 3:00:00 AM7/11/00
to
Hi, everyone
Could someone tell me how to set the list for a combo to a field in a DB
table. I have the DB (Access) connected up but I need to get the list values
from a field in the table (query actually) and put them into a drop down
box.

Any help much appreciated.

Cheers
Marcus

freeserve

unread,
Jul 11, 2000, 3:00:00 AM7/11/00
to
add ado components to your toolbox
Try adding a Ado data recordset and use a datacombo to your form and then
connecting that to your dataset.
Now make combobox.recordsource = Ado data recordset object
make the list source the field you require.

Marcus Booth <marcu...@dingoblue.net.au> wrote in message
news:396b16dc$0$11167$7f31...@news01.syd.optusnet.com.au...

Marcus Booth

unread,
Jul 12, 2000, 3:00:00 AM7/12/00
to
Thanks I had a go at that but I dont think I fully understood what you
meant. I have added a Data Combo but its properties are some what different
could you possible domb it down a little for me as this VB to DB stuff is a
bit new to me.

Cheers
Marcus


William R Highfield

unread,
Jul 12, 2000, 3:00:00 AM7/12/00
to
On Tue, 11 Jul 2000 22:47:35 +1000, "Marcus Booth"
<marcu...@dingoblue.net.au> typed and posted to
comp.lang.basic.visual.database:

>Hi, everyone
>Could someone tell me how to set the list for a combo to a field in a DB
>table. I have the DB (Access) connected up but I need to get the list values
>from a field in the table (query actually) and put them into a drop down
>box.
>
>Any help much appreciated.
>
>Cheers
>Marcus
>

This assumes that you are using an Access97-95 database and want to do
it with code only.

Private Sub LoadComboBox()

' make a reference to the DAO 3.51 Library under the menu:
' Project - References

' this expects the there is a display column in the recordset
' and there is a Long Integer as the Primary Key

' no error handling for space

Dim db As DAO.Database
Dim qry As DAO.QueryDef
Dim rs As DAO.Recordset
Dim m_lngPK As Long

Set db = OpenDatabase("<PATH-TO-DATABASE>", False, False)

Set qry = db.QueryDefs("<YOUR-QUERY-NAME>")

Set rs = qry.OpenRecordset(dbOpenForwardOnly)

With rs
Do While Not .EOF
Combo1.AddItem !DisplayColumnName
Combo1.ItemData(Combo1.NewIndex) = !PrimaryKeyColumnName
.MoveNext
Loop

.Close
End With

' to use the ItemData feature:

m_lngPK = Combo1.ItemData(Combo1.ListIndex)

End Sub

Hope this helps


0 new messages