List Boxes

TanyaG
TanyaG used Ask the Experts™
on
Hello once again.

I have 2 list boxes.  One list box contains a bunch of products from an access table called ProductTable. The user is to highlight one item in the Product list, then they press add item, then the item is sent to the Order List. etc etc.  The code I am using is as follows but it only chooses the first item in the database... What am i doing wrong this time?  :(


 If lstProducts.Text <> "" Then                        With lstDescription
   .AddItem rsGetData!ProdNum & "" & rsGetData!ProdDesc
 End With
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Are you trying to add it to the list box or the database or both?

Commented:
there might be a problem in your 'add item' button. how do you send it to order list?

could you give us a better full view of your code?

-rgenius

Author

Commented:
This is my add item button:

Private Sub AddItem_Click()
rsGetData.MoveFirst

 If lstProducts.Text <> "" Then
           
    With lstDescription
           .AddItem rsGetData!ProdNum & " " & rsGetData!ProdDescription & " " & _
           rsGetData!ProdPrice & "" & rsGetData!ProdQuantityRemaining
      End With
End If
End Sub

And I populate my first listbox like this:

'loads list box with productTable items
With rsGetData
 Do Until .EOF
  If !ProdNum <> PrevProd Then  'no duplicates
    lstProducts.AddItem !ProdNum & " " & !ProdDescription
      PrevProd = !ProdNum
  End If
  .MoveNext
 Loop

End With
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
Ok her'e the code which I think may help you

'---To populate the products list box

rstProducts.open "Select * from ProductTable"

Do while not rstProducts.EOF
   lstProducts.addItem rstProducts!ProdNum & " " & rstProducts!ProdDesc
   lstProducts.ItemData(lstProducts.NewIndex) = rstProducts!ProductID
   rstProducts.movenext
loop


Now when someone clicks the Add button

If lstProducts.text <> "" then
  '--This to add to your OrderList ListBox
   lstOrderList.AddItem lstProducts.Text
   lstOrderList.ItemData (lstOrderList.NewIndex) = lstProducts.ItemData(lstProducts.ListIndex)
 Endif

I'm guessing thsi is wht you want..

Author

Commented:
This is my add item button:

Private Sub AddItem_Click()
rsGetData.MoveFirst

 If lstProducts.Text <> "" Then
           
    With lstDescription
           .AddItem rsGetData!ProdNum & " " & rsGetData!ProdDescription & " " & _
           rsGetData!ProdPrice & "" & rsGetData!ProdQuantityRemaining
      End With
End If
End Sub

And I populate my first listbox like this:

'loads list box with productTable items
With rsGetData
 Do Until .EOF
  If !ProdNum <> PrevProd Then  'no duplicates
    lstProducts.AddItem !ProdNum & " " & !ProdDescription
      PrevProd = !ProdNum
  End If
  .MoveNext
 Loop

End With

Author

Commented:
AWSOME!  Thanks sooo much! That worked perfectly and now I understand how to set up SQL statement a lot more clearly now.   Thanks guys!    :)    

Author

Commented:
If the user double clicks on an item in the list box, is there a statement that can do the same thing?   Some pseduo code for you:

If item in list box double clicked
    add that item to Order list box
end if

Commented:
In the lstProducts_DblClick() Event put this
  Call  AddItem_Click

That should help

Author

Commented:
thank you and to rgenius, I am first adding the items to one list box and then once the order if verified..(The user can delete items, and an inventory is verified that there are enough products available) then I will adding the order to an order details table that will be used to create an invoice for the customer.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial