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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can we have strings and numbers in one list box

Status
Not open for further replies.

rbasram

Programmer
Sep 27, 2001
53
CA
I have a list box I want to know if we can store numbers and strings in two different colums of the same list box

like like name of products in one colum and the count of the products in the other column.
 
Sure, it's possible.

Are your products and counts stored in a table or query? If so, just set the controlsource of your listbox to that table/query with 2 columns defined pointing to those fields.

The wizard can step you through this if you've never done it before on your own.

Maq B-)
<insert witty signature here>
 
The way I have set up the lst box is that :

First of all I have a list box I select the products and move to the other lst box2.

In lstbox2 the product that are in there I use a dcount fuction to get the count.
That means all I want to is to loop through the products selected and then get the dcount fuction. I am getting an error in the dcount fuction it tell me type mismatch.
Here is some part of the code.
The count is a number and the product os the string.

Dim Totals As Integer
Dim intItem As Integer

For intItem = 0 To Me!lstBox2.ListCount - 1
Totals = DCount(&quot;[Product]&quot;, &quot;Table&quot;, &quot;[Product]= '&quot; & Me!lstAllProduct & &quot;'&quot;)
Totals = Totals & Me!lstBox2.Column(0, intItem) & &quot;;&quot; & Me!lstBox2.Column(1, intItem)<<--- Type mismatch error
Me!lstBox2.RowSource = Totals + 1

Next intItem


Please help...
 
Your type mismatch is caused because you are trying to put strings into an integer variable. Try something like this.

Dim totals as integer
Dim lstStr as string
Dim intItem as integer

Code:
lstStr = &quot;&quot;
For intItem = 0 To Me!lstBox2.ListCount - 1
   Totals = DCount(&quot;[Product]&quot;, &quot;Table&quot;, &quot;[Product]= '&quot; & Me!lstAllProduct & &quot;'&quot;)
   lstStr = lstStr & Me!lstBox2.Column(0, intItem) & &quot;;&quot; & Totals
Next intItem
Me!lstBox2.RowSource = lstStr

Maq B-)
<insert witty signature here>
 
oops, you need one more &quot;;&quot; on the lstStr row to prevent &quot;jumbled&quot; columns.


lstStr = &quot;&quot;
For intItem = 0 To Me!lstBox2.ListCount - 1
Totals = DCount(&quot;[Product]&quot;, &quot;Table&quot;, &quot;[Product]= '&quot; & Me!lstAllProduct & &quot;'&quot;)
If intItem <> 0 then lstStr = lstStr & &quot;;&quot;
lstStr = lstStr & Me!lstBox2.Column(0, intItem) & &quot;;&quot; & Totals
Next intItem
Me!lstBox2.RowSource = lstStr

Maq B-)
<insert witty signature here>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top