Listbox selection based on a table (1 Viewer)

Arvidsson

Registered User.
Local time
Today, 20:39
Joined
Jun 12, 2014
Messages
54
Hello,

I need support one more time :)

I have a form with a listbox that allowed multiselection.
The listbox depends on the field "name"
And I have a table "names_should_be_selected" (fields: name, date ...)

It would be great if alle names in the listbox are selected when the name is in the table "names_should_be_selected".

I have searched for this question in the internet, unfortunately i found no solution.

I would be very glad if someone has an idea. :)

Thank you very mich in advance!
 

Arvidsson

Registered User.
Local time
Today, 20:39
Joined
Jun 12, 2014
Messages
54
Sorry. I used this words to keep it simple.

I will try it one more:

I have a table:
-> tblProducts
products_name
products_price
products_deliverydate

I have a form where I can select some products for a query
-> frmSelectProducts
With a listbox
-> lstProducts
products_name
products_price
products_deliverydate
(sorted by products_name)

I have a table which is filled with the bestseller
-> tblBestseller
products_name

And I want that the bestseller are already selected in the lstProducts if I open the frmSelectProducts.
(Than I have not to select the most used products every time)

I hope I could clarify my question.
 

pr2-eugin

Super Moderator
Local time
Today, 20:39
Joined
Nov 30, 2011
Messages
8,494
Try this,
Code:
Public Sub SelectBestSeller(myList As ListBox)
On Error GoTo Err_Handler
   [COLOR=Green] 'Author:    Paul Eugin Francis.[/COLOR]
    Dim rowInd As Long
    For rowInd = 0 To myList.ListCount - 1
        If DCount("*", "tblBestseller", "products_name = '" & myList.ItemData(rowInd) & "'") <> 0 Then _
            myList.Selected(rowInd) = True
    Next

Exit_Handler:
    Exit Sub

Err_Handler:
    MsgBox "Error (" & Err.Number & ") - " & Err.Description
    Resume Exit_Handler
End Sub
Call this Sub in the Form Current method. Like
Code:
Private Sub Form_Current()
    SelectBestSeller lstProducts
End Sub
 

Users who are viewing this thread

Top Bottom