Hi
I have linked the combo box to the data control and the combo reads values from the database however dont know how to make the values list within the combo box. Any suggestions would be really appreciated!?!?!
Thanks
Roshny
Printable View
Hi
I have linked the combo box to the data control and the combo reads values from the database however dont know how to make the values list within the combo box. Any suggestions would be really appreciated!?!?!
Thanks
Roshny
Welcome to the forums. :)
I don't use bound controls, so I don't know that much about them, but I always thought the purpose of a bound control was to automatically populate controls, so I'm guessing that linking isn't the same as binding.
When you say you have a combo box "linked" to a database [field], what do you mean?
Do you know how to create and run a query and build a recordset from the results?
If I am not mistaken, bound fields only apply to the current record, not all the records in the data set. I think you will need to use an unbound combox box and fill it with a select statement and a loop.
I think this might be what you are looking for...
Set recordSet = New ADODB.recordSet
SQLQuery = "select * from TABLE"
recordSet.Open SQLQuery, connection, adOpenStatic
If (recordSet.EOF = True And recordSet.BOF = True) Then
Print "No records"Else
Do Until recordSet.EOF = TrueEnd If
data = recordSet.Fields("TABLE_DATA")Loop
comboBox1.AddItem data
recordSet.MoveNext
recordSet.Close
put this in form activate
with data1.recordset
.movefirst
while not .eof
combo1.additem .fields (0)
.movenext
wend
end with
G'day,
I am working on the same thing at the moment and here is my subroutine. Maybe you can work out something to suit your case.
cmbContact is a combobox
Contact is a field in my database called tblContacts
VB Code:
[color=#0d5692][color=#0d5692]Private Sub cmbContact_GotFocus(Index As Integer) Dim Temp As Integer dtaContacts.RecordSource = "SELECT * FROM tblcontacts where Contact like '" & CustName & "*' " dtaContacts.RecordSource = "select * from tblContacts" With dtaContacts.Recordset .MoveLast Temp = dtaContacts.Recordset.RecordCount .MoveFirst For i = 1 To Temp cmbContact.Item(Index).AddItem .Fields!Contact .MoveNext Next End With End Sub[/color][/color] [color=#0d5692][/color]
Peter
G'day,
Don't know what happened to previous post. Try this.
Private Sub cmbContact_GotFocus(Index As Integer)Dim Temp As Integer
dtaContacts.RecordSource = "select * from tblContacts"
With dtaContacts.Recordset
.MoveLast
Temp = dtaContacts.Recordset.RecordCount
.MoveFirst
For i = 1 To Temp
cmbContact.Item(Index).AddItem .Fields!Contact
.MoveNext
Next
End With
End Sub