有没有办法缩短这个VBA:
Me.cboDeptU1.AddItem "1"
Me.cboDeptU1.AddItem "2"
Me.cboDeptU1.AddItem "3"
Me.cboDeptU1.AddItem "4"
Me.cboDeptU1.AddItem "5"
Me.cboDeptU.SetFocus
我也在同一个Sub中有这个:
Me.cboDeptL1.AddItem "1"
Me.cboDeptL1.AddItem "2"
Me.cboDeptL1.AddItem "3"
Me.cboDeptL1.AddItem "4"
Me.cboDeptL1.AddItem "5"
Me.cboDeptL.SetFocus
答案 0 :(得分:5)
替换
Me.cboDeptU1.AddItem "1"
Me.cboDeptU1.AddItem "2"
Me.cboDeptU1.AddItem "3"
Me.cboDeptU1.AddItem "4"
Me.cboDeptU1.AddItem "5"
使用
For i = 1 to 5
Me.cboDeptU1.AddItem Cstr(i)
Next i
答案 1 :(得分:2)
如果您只是将这些项目添加到完全空List
,则可以使用以下内容:
Me.cboDeptU1.List = Array("1", "2", "3", "4", "5")
答案 2 :(得分:0)
这可能是您的首选资源。
http://www.fontstuff.com/access/acctut20.htm
http://www.fontstuff.com/access/acctut13a.htm
而且......对于ListBoxes ......