PDA

Click to See Complete Forum and Search --> : Display data in a combobox


visualsander
Oct 13th, 2000, 09:00 AM
Hi group,

For the last couple of hours(!!!) I am trying to show the contents of a table in a combo box.

I have table with 2 fields:
* FunctieID
* FunctieDescription

I tried a couple of SQL statements:

SELECT tblFunctie.FunctieID, tblFunctie.Description

And

SELECT tblFunctie.FunctieID, tblFunctie.Description FROM tblFunctie

I put them in the combobox property: datafield and/or datasource.

Result => nothing.

Why doesnt this work. By the way I am using the ADO method.

Sander

vbuser1976
Oct 13th, 2000, 01:16 PM
Well, first of all, your SQL statement are wrong. You do not have to put the tablename as part of the field name(Select tblone.fieldone, tblone.fieldtwo from tblone). If the table has only those two fields, can make your SQL Statement like this:
Select * from tblone or
Select fieldone,fieldtwo from tblone

I have a lengthy solution to your problem so bear with me. The way I set up to populate my combo box was to use a stored procedure and a set up connection in form load.

Hope this helps.

Below is code:
##########################################################
Option Explicit
Private cn As ADODB.Connection
Private rs As ADODB.Recordset

Private Sub Form_Load() 'Opens the database and populates the combobox
Set cn = New Connection
cn.Open "PROVIDER=MSDASQL;dsn=QCManager;uid="sa";pwd="";
database=[name of your dB];"
Set rs = New ADODB.Recordset
rs.LockType = adLockOptimistic
rs.CursorType = adOpenKeyset
PopulateComboBox
End Sub

Private Sub PopulateComboBox() 'This procedure runs a loop to populate the combobox
Dim rs As ADODB.Recordset
Dim cm As ADODB.Command

Set cm = New ADODB.Command
Set cm.ActiveConnection = cn
cm.CommandType = adCmdStoredProc
cm.CommandText = "enter name of stored procedure here"
Set rs = cm.Execute

'Comboboxname.Clear
cbAtmId.Clear
Do Until rs.EOF
cbAtmId.AddItem rs.Fields("AtmId")
rs.MoveNext
Loop

rs.Close
Set rs = Nothing
End Sub