Any help much appreciated.
Cheers
Marcus
Marcus Booth <marcu...@dingoblue.net.au> wrote in message
news:396b16dc$0$11167$7f31...@news01.syd.optusnet.com.au...
Cheers
Marcus
>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