-
Nov 28th, 2000, 05:30 AM
#1
Thread Starter
Hyperactive Member
I have a table with product and product code. The product code is a string - not integer.
I want to populate a listbox (or combobox - dont know what is best) with the names AND codes of the products in my table so that when the user clicks on a specific productname/code I can select that specific one and display it's details.
I know how to display the name OR the code in the listbox - how do I do both!!??
while not rs.eof
lstbox.additem (rs!name)
rs.movenext
wend
How can I know what record the user selected!!?? I need to know this so that I can get that products specific info and display it.
Thank you,
T
-
Nov 28th, 2000, 05:48 AM
#2
Member
Use the listindex property
If you add the product code and product seperately to two list boxes in one loop you can use the listindex of both combo boxes is the same.
To be sure you also use the Itemdata property of both combo boxes to store the new listindex value of the other combobox which item was added.
Code:
cmbProduct.Additem rs!Name
cmbCode.Additem rs!Code
cmbProduct.Itemdata(cmbProduct.NewIndex) = cmbCode.NewIndex
cmbCode.Itemdata(cmbCode.NewIndex) = cmbProduct.NewIndex
Same goes for listindex controls
You could also consider adding a autonumber field to the table, this always creates a unique long number ID for the record to reference to. You can still use the Code field as your Primary Index.
Hope this helps
A mind is like a parachute, it has to open to let it work
www.2beesoft.com for Icon Manager with over 20.000 free icons
VB6 Ent. SP4, ASP, W2000/W98
-
Nov 28th, 2000, 05:53 AM
#3
Fanatic Member
-
Nov 28th, 2000, 05:54 AM
#4
PowerPoster
Multi Column Listbox
May be you can use the multi Column listbox as show below, but when a use selected a item from the listbox, you need to split the name and code before you proceed to fatch the related data.
Code:
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_SETTABSTOPS = &H192
Private Sub Command1_Click()
Call SendMessage(List1.hwnd, LB_SETTABSTOPS, 1, 100)
While not rs.eof
lstbox.additem rs!name & vbTab & rs!code
rs.movenext
wend
Private Sub Command2_Click()
SplitData (List1.List(List1.ListIndex))
End Sub
Private Sub SplitData(ByVal sData As String)
Dim i As Integer
Dim itm(1) As Variant
Dim iArray As Variant
Dim idata As Variant
iArray = Split(sData, vbTab, -1, vbTextCompare)
i = 0
For Each idata In iArray
itm(i) = idata
i = i + 1
Next
MsgBox "Selected product name is " & itm(0) & " with code = " & itm(1)
End Sub
-
Nov 28th, 2000, 07:11 AM
#5
Thread Starter
Hyperactive Member
Thank you all for the help!! It will help a lot
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|