|
-
Apr 11th, 2005, 10:04 AM
#1
Thread Starter
New Member
Inserting values from a database to combo box
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
-
Apr 11th, 2005, 11:02 AM
#2
Re: Inserting values from a database to combo box
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?
-
Apr 11th, 2005, 11:50 AM
#3
PowerPoster
Re: Inserting values from a database to combo box
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.
-
Apr 14th, 2005, 11:30 PM
#4
New Member
Re: Inserting values from a database to combo box
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 = True
data = recordSet.Fields("TABLE_DATA")
comboBox1.AddItem data
recordSet.MoveNext Loop End If
recordSet.Close
Last edited by manbeast7; Apr 14th, 2005 at 11:37 PM.
-
Apr 14th, 2005, 11:52 PM
#5
Hyperactive Member
Re: Inserting values from a database to combo box
put this in form activate
with data1.recordset
.movefirst
while not .eof
combo1.additem .fields (0)
.movenext
wend
end with
-
Apr 15th, 2005, 12:41 AM
#6
Hyperactive Member
Re: Inserting values from a database to combo box
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
-
Apr 15th, 2005, 12:45 AM
#7
Hyperactive Member
Re: Inserting values from a database to combo box
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
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
|