source data for a combo box

M

meg99

using 2003. I have a user form with a combo box. I want the combo
box to display the available calendars. Here is my code for that:

Dim CalCnt As Integer, c As Integer
Dim CalArray() As String

CalCnt = ActiveProject.BaseCalendars.Count
For c = 1 To CalCnt
ReDim CalArray(c)
CalArray(c) = ActiveProject.BaseCalendars.Item(c).Name
Next c

I want to set the combox data source to CalArray. However, when I
enter CalArray in the Control Source or Row Source, I get an error
message - "Invalid Propvery Value."

How can I do this?


meg99
 
J

John

meg99 said:
using 2003. I have a user form with a combo box. I want the combo
box to display the available calendars. Here is my code for that:

Dim CalCnt As Integer, c As Integer
Dim CalArray() As String

CalCnt = ActiveProject.BaseCalendars.Count
For c = 1 To CalCnt
ReDim CalArray(c)
CalArray(c) = ActiveProject.BaseCalendars.Item(c).Name
Next c

I want to set the combox data source to CalArray. However, when I
enter CalArray in the Control Source or Row Source, I get an error
message - "Invalid Propvery Value."

How can I do this?


meg99

meg99,
First of all you don't want to re-dimension the array inside the loop.
If it works at all, it will not give you what you expect. For starters,
the ReDim statement zeros out the array.

The following code structure is better:

Dim CalArr() As String
Dim CalCnt As Integer, c As Integer
CalCnt = Application.GlobalBaseCalendars.Count
ReDim CalArr(CalCnt)
For c = 1 To CalCnt
CalArr(c) = Application.GlobalBaseCalendars(c).Name
Next c
End Sub

Hope this helps.
John
Project MVP
 
J

Jack Dahlgren

Instead of building the array, just keep adding the items to the list box
inside your for loop.

-Jack
 
R

Rod Gill

Yes, use the additem method, but that only works if you want a single
column. If you want a multi-column combo box (EG Calendar name then
description, you need to use the Array you have built, but obviously with
one dimension per column. Then use:

MyComboBox.List=CalArray

--

Rod Gill
Project MVP

Project VBA Book, for details visit:
http://www.projectvbabook.com

NEW!! Web based VBA training course delivered by me. For details visit:
http://projectservertraining.com/learning/index.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top