Controlling user entry in Excel user form combo boxes

I have an Excel user form with two combo boxes ('Task' and 'Status'):
> I tried to set the Style property of both combo boxes to 2 - fmStyleDropDownList to restrict the user to only selecting entries from the dropdown box and not being able to place their cursor in the field and remove or enter text.
> The 'Status' combo box appears to work without generating an error message
> The 'Task' combo box now gives me the following error message when I go to select an item from the dropdown menu:

Run-time error '380'
Could not set the Text property. Invalid property value.


When I click on Debug, it points me to a highlighted line:

    .Text = .List(.ListIndex, 1)

Open in new window


As I am not very savvy in this area, I have attached the Excel file with the user form in question to demonstrate what is happening.

Please let me know if you need any more information.

Thanks,
Andrea
Task_Plan_EE.xlsm
AndreamaryAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Try it like this...

.Text = .List(.ListIndex, 0)

Open in new window

AndreamaryAuthor Commented:
Hi Subodh,

Thanks for the quick response! I tested the solution, and while it fixes the issue, it has changed the way the Task field is populated. Instead of being populated with the Task, it is being populated with the ID number. I set up the 3-column dropdown, etc. with the help of this forum, and during the course of the solution, a 'hidden' field was added to the user form which may be impacting this behaviour...? See screen captures below.

Is it possible for the task field to revert to being populated by the task, as per the original user form, but still benefit from the solution you have provided?

TaskField.PNG
HiddenField.PNG
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Actually the ComboBox will display the content of the first column.
To display the Task which is second column in the ComboBox list, all you can do is, change the order of columns i.e. Task, ID and PA Unit instead of ID, Task and PA Unit.

In the attached, I created a table with desired column order in range M:O (Columns are hidden) on Task Sheet.
And then created a named range called "TaskCombo" which I used as the RowSource for the cboTask.
I also commented out the code in UserForm Initialize event which sets the cboTask ComboBox properties as it is not required now.

See if this is something you can work with.
Task_Plan_EE.xlsm

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AndreamaryAuthor Commented:
Perfect...thanks very much for the solution and explanation, Subodh!

Cheers,
Andrea
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Andrea! Glad I could help.
Thanks for the feedback.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.