PDA

View Full Version : Work Form ComboBox -Using an Array instead of .AddItem



Presto
05-22-2007, 01:31 PM
VBA Newbie needs your help!:help

I am creating a template file with a form to aid support staff to create a report. It contains a form that has several comboboxes on it.

In the code, you will see a total of 10 combo boxes that use the same information. I would like to find a more efficient way to list the items just once in the code to 1. reduce the file size, and 2. reduce the amount of editing time since these items may change on occasion.

I was hoping to use an array if possible but have no experience with them.

Any ideas?

PS... I love this site....

fumei
05-22-2007, 11:47 PM
Dim strTopics()
Dim oCtl As Control
Dim var, var2
strTopics = Array("Address Change - Processing", _
"Address Change - Systems", _
"Correspondence - Faxing / Mailing", _
"Correspondence - General Letters", _
"Correspondence - Letters / Forms", _
"Correspondence - W9", "FollowUp Call - Short Comments", _
"FollowUp Call - Workflow", "Forms/Letters", _
"Misc", "Products", "PSC - CC Payments", _
"PSC - Group Billing", "PSC - Individual", _
"PSC - Lockbox/Overnight", "PSC - PAC Service", _
"PSC - Payment Inquiry", "Resources", _
"Sales Lead", "Security - Third Party", _
"Security - Verification", "Self Service ", _
"Service Alert", "Tax - 1099's ", _
"Tax - Form 712", "Values", _
"W9")
For var = 1 To 5
For var2 = 0 To UBound(strTopics)
Me.Controls("cboTopic" & var).AddItem strTopics(var2)
Next
Next
1. make the array of the values

2. For var = 1 to 5
for 1 to 5 - make "cboTopic" & 1..to ...5 (cboTopic1, cboTopic2...etc, to cboTopic5) This is var

3. For var = 0 To Ubound(strTopics)
.AddItem for each item in the array. This is var2, each item in the array

That should help you get going.

I am sorry, and I hope you are not horribly offended....but I just hate your form. I looked at it only long enough to get your values...then closed it.

WHY did you rename the ThisDocument module???????????

Presto
05-23-2007, 04:15 AM
This worked perfectly!!! Thanks a million!!
Thanks for getting the code started. I've just started learning to do code.



WHY did you rename the ThisDocument module???????????



..Well.. I did mention I was a newbie. At the time I was working on this, I had many other documents open and I figured I would name this one something to easily identify it.

And the design of the form.... well,,, no offense taken. As you can see... I am not a "designer" :dunno but if you looked at some stuff here that others threw together you would think this one is perfect. At least mine makes some sense compared to the setup of the report (which I didn't design.).

If you would like to redesign it to look more professional, go right ahead. :yes

fumei
05-23-2007, 08:33 AM
No thanks.

Your users must have gigantic monitors and high resolution. The form is not fully visible on my system because it is HUGE!

The colours are...interesting.

Presto
05-23-2007, 09:37 AM
I didn't think about resolution before.. good thing you brought it up.

Yeah, our monitors are 17 or 19 inch at 1152 x 864 pixels. We have *many* screens open at one time so desktop needs to be high res.
but I suppose I could make the form a little smaller. :)

Colors.. (I feel your pain there).... we have different reports to do throughout the week. Each business unit has it's own color scheme.
Hey... I just do what the boss tells me to do. It's not my call.

Norie
05-23-2007, 01:11 PM
Why 10 comboboxes?

Couldn't this be done with listboxes/textboxes, maybe even a multipage?

fumei
05-24-2007, 11:09 PM
Hi Norie.

You betcha.