Option Explicit Dim i As IntegerPrivate Sub Command1_Click() i = i + 1 If i > Combo1.ListCount - 1 Then i = 0 Combo1.ListIndex = i
End SubPrivate Sub Form_Load() With Combo1 .AddItem "AAA" .AddItem "BBB" .AddItem "CCC" End With
Combo1.ListIndex = 0End Sub
得到当前值 dim str$,str=Combo1.text
帮我看看这段程序,有问题吗? rs.Open (sql)
If rs.EOF Then OutSetCellList.AddItem ("没有任何单元") Else Do Until rs.EOF OutSetCellList.AddItem (rs("cellname"))
If setDYid = rs("cellid") Then
OutSetCellList.Text = rs("cellname")
End If
rs.MoveNext
Loop
End If rs.Close运行就出现run-time error '91' object variable or with block variable not set如果把“OutSetCellList.Text = rs("cellname")”去掉就正常
不能这样写:combobox.text=rs("field") 应该: for i=0 to combo1.listcount-1 if combo1.list(i)=rs("field") then combo1.listindex=i endif next
OutSetCellList.Text = rs("cellname") 用下面代替就得了 for i=0 to OutSetCellList.listcount-1 if OutSetCellList.list(i)=rs("cellname") then OutSetCellList.listindex=i endif next
2。应该是combobox1.additem "string"
combobox.text=rs("field")
这样写对吗?
Dim i As IntegerPrivate Sub Command1_Click()
i = i + 1
If i > Combo1.ListCount - 1 Then i = 0
Combo1.ListIndex = i
End SubPrivate Sub Form_Load() With Combo1
.AddItem "AAA"
.AddItem "BBB"
.AddItem "CCC"
End With
Combo1.ListIndex = 0End Sub
rs.Open (sql)
If rs.EOF Then
OutSetCellList.AddItem ("没有任何单元")
Else
Do Until rs.EOF
OutSetCellList.AddItem (rs("cellname"))
If setDYid = rs("cellid") Then
OutSetCellList.Text = rs("cellname")
End If
rs.MoveNext
Loop
End If
rs.Close运行就出现run-time error '91'
object variable or with block variable not set如果把“OutSetCellList.Text = rs("cellname")”去掉就正常
应该:
for i=0 to combo1.listcount-1
if combo1.list(i)=rs("field") then
combo1.listindex=i
endif
next
if OutSetCellList.list(i)=rs("cellname") then
OutSetCellList.listindex=i
endif
next
Dim add$
Combo1.Clear
Do Until adoRS.EOF
add$ = adoRS![字段]
Combo1.AddItem add$
adoRS.MoveNext
Loop
2. Combo1.ListIndex = 0 把第一项加入框中,一般在窗体的Load事件里写上就行了