multiple query field into one list box

ice051505

Registered User.
Local time
Yesterday, 23:05
Joined
Feb 11, 2013
Messages
42
Hi dear all, I have a optional group with 3 buttons and one list box. my query has 4 fields: A1, A2, A3, A4. I want to know if that possible to show A1&A2 in the list box after click the optional group button1, and then if I click optinal button2, field A2&A3 will shows in my list box, and so on. How do I write the code? Hope anyone can help me, Thanks!
 
On each of the three button's Click events, scan through all three buttons checking their state checked / not checked, and build a string as you process with the checked boxes you encounter.

Oh, did you mean Push Button controls or Check Box controls? At first I was thinking you were talking about Check Box controls, have a checked / unchecked state.
 
You can redefine the Row Source of the list box in the Click event of the command buttons. Example;

Code:
Private Sub cmdButton1_Click()

    Dim strSQL As String

    strSQL = "Select A1, A2 From YourTable;"
    
    Me!lstYourListBox.RowSource = strSQL

End Sub

Private Sub cmdButton2_Click()

    Dim strSQL As String

    strSQL = "Select A2, A3 From YourTable;"
    
    Me!lstYourListBox.RowSource = strSQL

End Sub
 
Not quite sure what you referring to, but is this an option

Click on the box you want to trigger an event
Click on propertioes
Select Events, After Update

Now you can add the code
MyListbox.Additem = A & B
 
Thanks Beetle, it worked, but I just got another problem that there is duplicate data in the field A2&A3, when I get my list box, how do I keep all the data in field A1&A2 and then eliminate the duplicates while the list box shows field A2&A3?


You can redefine the Row Source of the list box in the Click event of the command buttons. Example;

Code:
Private Sub cmdButton1_Click()
 
    Dim strSQL As String
 
    strSQL = "Select A1, A2 From YourTable;"
 
    Me!lstYourListBox.RowSource = strSQL
 
End Sub
 
Private Sub cmdButton2_Click()
 
    Dim strSQL As String
 
    strSQL = "Select A2, A3 From YourTable;"
 
    Me!lstYourListBox.RowSource = strSQL
 
End Sub
 
Try adding a Group By clause to the SQL for the secondary row source;

Code:
Private Sub cmdButton1_Click()

    Dim strSQL As String

    strSQL = "Select A1, A2 From YourTable;"
    
    Me!lstYourListBox.RowSource = strSQL

End Sub

Private Sub cmdButton2_Click()

    Dim strSQL As String

    strSQL = "Select A2, A3 From YourTable " _
           & "Group By A2, A3;"
    
    Me!lstYourListBox.RowSource = strSQL

End Sub
 

Users who are viewing this thread

Back
Top Bottom