load combo (urgent) (vb6)

04-19-2004, 12:10 PM
i have 2 tables in assces, "Category" and "Main" . i am able to open main and use and navigate its data, , i am trying to put a combo box which displays values from Category table, in the same form,...plz help, example will be good

04-19-2004, 01:01 PM
Dim cn as ADODB.connection
Dim rs as ADODB.recordset
Dim sSQL as string

sSQL = "SELECT * FROM Category"

Set cn = New ADODB.connection
Set rs = New ADODB.recordset

cn.connectionString = "YOUR ADO CONNECTION STRING"

rs.Open sSQL, cn, adOpenkeyset, adLockOptimistic, adCmdText

If Not rs.EOF = 0 Then
msgbox "no records found"
Exit sub
End With

While rs.EOF = False
combo1.AddItem rs.Fields("field1").value

set rs = nothing
set cn = nothing

04-20-2004, 10:46 AM
i have opened and set recordset in load event and in load data event where i am loading data from Main, i am using combo, when i put the code there to load, it gives error (item not found)

04-20-2004, 11:28 AM
because in your module where you add the combo box data the recordset object is not instantiated...it is equal to nothing. It becomes a matter of scope. If in your form load you are not populating anything, don't open the recordset there. Only open the recordset where you need it (in the module where you populate your combo box and other controls) and then, when no longer needed, close the recordset and set its object equal to nothing.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum