David Quetglas
David Quetglas

Reputation: 87

Adding ComboBox items

Is there a way to shorten this VBA:

Me.cboDeptU1.AddItem "1"
Me.cboDeptU1.AddItem "2"
Me.cboDeptU1.AddItem "3"
Me.cboDeptU1.AddItem "4" 
Me.cboDeptU1.AddItem "5"

Me.cboDeptU.SetFocus 

I also have this one in the same Sub:

Me.cboDeptL1.AddItem "1"
Me.cboDeptL1.AddItem "2"
Me.cboDeptL1.AddItem "3"
Me.cboDeptL1.AddItem "4"
Me.cboDeptL1.AddItem "5"

Me.cboDeptL.SetFocus 

Upvotes: 2

Views: 79

Answers (3)

ASH
ASH

Reputation: 20352

This is probable your go-to resource.

http://www.fontstuff.com/access/acctut20.htm

http://www.fontstuff.com/access/acctut13a.htm

And...for ListBoxes...

http://www.fontstuff.com/access/acctut11.htm

Upvotes: 0

YowE3K
YowE3K

Reputation: 23994

If you were only adding these items to a completely empty List, you could use something like:

Me.cboDeptU1.List = Array("1", "2", "3", "4", "5")

Upvotes: 2

Shmukko
Shmukko

Reputation: 592

Replace

Me.cboDeptU1.AddItem "1"
Me.cboDeptU1.AddItem "2"
Me.cboDeptU1.AddItem "3"
Me.cboDeptU1.AddItem "4" 
Me.cboDeptU1.AddItem "5"

With

For i = 1 to 5
  Me.cboDeptU1.AddItem Cstr(i)
Next i

Upvotes: 5

Related Questions