Hi
Set rs = New ADODB.Recordset
If rs.State = 1 Then rs.Close
rs.Open "temp", cnn, adOpenDynamic, adLockOptimistic, adCmdTable
On the line
cmb1.Text = rs!name
it is giving error "Text property is read-only."
Thanks
Printable View
Hi
Set rs = New ADODB.Recordset
If rs.State = 1 Then rs.Close
rs.Open "temp", cnn, adOpenDynamic, adLockOptimistic, adCmdTable
On the line
cmb1.Text = rs!name
it is giving error "Text property is read-only."
Thanks
Is it a normal combobox ?
What style is it set to ?
My quick test was style = 0, and I could do this -
Private Sub Form_Click()
Combo1.Text = "Rob"
End Sub
And "Rob" appeared
Rob
And I hope you are not using binding (If I have told you once, I have told you a million times "do not use binding")
If the style of the combo is drop down list then this can be an issue. I forget now if you can not set the text at all or if you can only set it to a member that is in the list already. No time to test it now but it is one or the other/ If you change the style you can modify the text or you can use the listindex property to change it.
As DataMiser says, Dropdown combo's text can only be derived from the existing list by using the list index property.
Try this sub
Code:Sub UpdateMyCombo(cmb as combobox, mytext as string)
dim i%
for i = 0 to cmb.listcount -1 'If its in the list already use it
If mytext = cmb.list(i) then
cmb.listindex = i
exit sub
end if
next i
cmb.additem mytext 'If not add it
cmb.listindex = cmb.listcount -1
end sub
Or use sendmessage with cb_findfirst. A lot faster than looping through the list