Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pre-select data in ListBox based on UserForm input

Status
Not open for further replies.

derekpax

Technical User
Sep 12, 2005
3
US
I have a UserForm where a person's name is selected and data is entered and stored in a database.

I want the UserForm to pre-load the data if the data has already been entered for a particular person.

After the name and corresponding data is found, I've been using:

ComboBox1.Value = ActiveCell.Value
TextBox1.Value = ActiveCell.Value

For ListBoxes I get the following error: "Could not set the Value property. Invalid property value."

The ListBox is not a multi-select ListBox

Any help would be appreciated




 
You have to loop through the contents of the combobox to determine which name the value should be set to. Comboboxes use .List and .ListIndex to determine the value displayed. Treat them as an array rather than a textbox. You need to determine which value in the Combobox is the one you want and then set the value of the Combobox to the position that the data occupies within the Combobox. The first item in a combobox is at position 0, not 1.

For boxsearch = 0 To UserForm1.ComboBox1.ListCount - 1
If UserForm1.ComboBox1.List(boxsearch) = ActiveCell.Value Then
UserForm1.ComboBox1.Value = UserForm1.ComboBox1.List(boxsearch)
UserForm1.textbox1.Value = ActiveCell.Value
Exit For
End If
Next boxsearch

Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top