ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Setting a list box to a value (https://www.excelbanter.com/excel-programming/372817-setting-list-box-value.html)

Riddler

Setting a list box to a value
 
I have 2 user forms that talk to each other. The first one has a
listbox that gets a list of values added from a range off of a sheet.
It is a list of suppleirs. The second user form looks up a RFQ# and
then I hit a command button to create a revision of the displayed RFQ
on Userform2. I set listboxes on userform1 equal to text boxes on
userform 2. My thought was that userform1 would have the complete list
of suppliers and then by setting userform1's listbox value equal to the
userform2 text box it would pre-select it on the list.

This works most of the time but I have 2-3 listboxes on userform1 that
show a selection has been made but when I check the value for that
listbox it comes back with "". The list box on userform1 is visible,
not locked, enabled. The real puzzler is that this glitch seems to move
around on 2-3 of my listboxes. It does not always happen the same
everytime.
I clicked on each of the listboxes on userform1 and looked at the
properties as compared to one that never gives me a problem. The only
difference I saw was that MatchEntry was not set the same. So I made
the trouble on match the good one with the Complete entry match
selection. I also tried a mix of listbox.value and .text to see if
that made a difference. No such luck.

'Load the current RFQ data onto the USERFORM1
UserForm1.ListBox1.Value = UserForm3.TextBox7.Text
UserForm1.ListBox2.Value = UserForm3.TextBox8.Text
UserForm1.ListBox3.Text = UserForm3.TextBox9.Value '.Text 'Product
Type
UserForm1.ListBox4.Text = UserForm3.TextBox11.Text
UserForm1.ListBox5.Text = UserForm3.TextBox10.Value '.Text
UserForm1.TextBox1.Text = UserForm3.TextBox1.Text
UserForm1.TextBox2.Text = UserForm3.TextBox2.Text
UserForm1.TextBox3.Text = UserForm3.TextBox3.Text
UserForm1.TextBox5.Text = UserForm3.TextBox5.Text
UserForm1.TextBox6.Text = UserForm3.TextBox6.Text
UserForm1.TextBox7.Text = UserForm3.TextBox13.Text

Any thoughts??

Thanks
Scott


Jim Cone

Setting a list box to a value
 
..Value is normally used to read what is selected in the list box.
The .Add method is normally used to add items to a list box.
I doubt if the following code actually does anything...
"UserForm1.ListBox1.Value = UserForm3.TextBox7.Text"
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"Riddler"

wrote in message
I have 2 user forms that talk to each other. The first one has a
listbox that gets a list of values added from a range off of a sheet.
It is a list of suppleirs. The second user form looks up a RFQ# and
then I hit a command button to create a revision of the displayed RFQ
on Userform2. I set listboxes on userform1 equal to text boxes on
userform 2. My thought was that userform1 would have the complete list
of suppliers and then by setting userform1's listbox value equal to the
userform2 text box it would pre-select it on the list.

This works most of the time but I have 2-3 listboxes on userform1 that
show a selection has been made but when I check the value for that
listbox it comes back with "". The list box on userform1 is visible,
not locked, enabled. The real puzzler is that this glitch seems to move
around on 2-3 of my listboxes. It does not always happen the same
everytime.
I clicked on each of the listboxes on userform1 and looked at the
properties as compared to one that never gives me a problem. The only
difference I saw was that MatchEntry was not set the same. So I made
the trouble on match the good one with the Complete entry match
selection. I also tried a mix of listbox.value and .text to see if
that made a difference. No such luck.

'Load the current RFQ data onto the USERFORM1
UserForm1.ListBox1.Value = UserForm3.TextBox7.Text
UserForm1.ListBox2.Value = UserForm3.TextBox8.Text
UserForm1.ListBox3.Text = UserForm3.TextBox9.Value '.Text 'Product
Type
UserForm1.ListBox4.Text = UserForm3.TextBox11.Text
UserForm1.ListBox5.Text = UserForm3.TextBox10.Value '.Text
UserForm1.TextBox1.Text = UserForm3.TextBox1.Text
UserForm1.TextBox2.Text = UserForm3.TextBox2.Text
UserForm1.TextBox3.Text = UserForm3.TextBox3.Text
UserForm1.TextBox5.Text = UserForm3.TextBox5.Text
UserForm1.TextBox6.Text = UserForm3.TextBox6.Text
UserForm1.TextBox7.Text = UserForm3.TextBox13.Text

Any thoughts??
Thanks
Scott


Riddler

Setting a list box to a value
 
I use the .additem to initially load the listbox and then use the .text
of it to make a selection through code. It works but as I stated not
consistently. Is there some other way to preselect a item in a listbox
using code when the list has already been created?

Thanks
Scott


Jim Cone

Setting a list box to a value
 
Scott,

Listbox1.ListIndex = 3 ' selects the fourth item

-1 is no selection
0 is the first item
Listbox1.ListCount -1 = number of items in list box
--
Jim Cone
San Francisco, USA
http://www.officeletter.com/blink/specialsort.html



"Riddler" wrote in message oups.com...
I use the .additem to initially load the listbox and then use the .text
of it to make a selection through code. It works but as I stated not
consistently. Is there some other way to preselect a item in a listbox
using code when the list has already been created?

Thanks
Scott


Riddler

Setting a list box to a value
 
The problem I have is that my list is something like this:
MES
McMaster Carr
Walmart
ABC Construction
A & B Supply

and then I want the second user form to say preselect "ABC
Construction".
I would have to write a routine to determine which line it is on in the
list box.
Just setting it equal to the other one seemed to make it preselect OK
except for those couple that I mention that just dont return what is
highlighted.

Thanks
Scott


Jim Cone

Setting a list box to a value
 
I think this is what you are trying to do, but I am not sure...
UserForm1.ListBox1.ListIndex = 3
UserForm2.Textbox1.Value = "Preselect " & UserForm1.Listbox1.Value

Jim Cone


"Riddler"
wrote in message
The problem I have is that my list is something like this:
MES
McMaster Carr
Walmart
ABC Construction
A & B Supply

and then I want the second user form to say preselect "ABC
Construction".
I would have to write a routine to determine which line it is on in the
list box.
Just setting it equal to the other one seemed to make it preselect OK
except for those couple that I mention that just dont return what is
highlighted.

Thanks
Scott


Riddler

Setting a list box to a value
 
I dont quite follow what you have shown.
What I am trying to do is have a listbox list filled up and then select
one of those items by its text. So from my list above of suppliers I
want to select say Walmart. All I am looking to do is preselect some
choices and then let the user change them as needed to create a
revision. The main function of my Excel program is a request for quote
# system and I want to be able to pull up a existing RFQ and then
create a revision of it So I was trying to take existing info and
preselect it and then let the user change as needed and take out a new
revision for the RFQ.

Thanks
Scott



All times are GMT +1. The time now is 12:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com