Run a query with value from cbobox to populate a listbox

MikeLeBen

Still struggling
Local time
Today, 18:08
Joined
Feb 10, 2011
Messages
187
I have been googling this for a while now, to no avail.

I am using a combobox in my form with this syntax to show customers who have placed orders:
Code:
SELECT DISTINCT Ordini.IDCliente, Clienti.CognomeContatto, Clienti.NomeContatto FROM Ordini, Clienti WHERE Ordini.IDCliente = Clienti.IDCliente ORDER BY Clienti.CognomeContatto;

I then want a listbox to show the orders on the Ordini table that have IDCliente as their foreign key, so I put this code in the afterupdate event of said cbobox:
Code:
Private Sub cboOrdiniCliente_AfterUpdate()

txtDataInserimento = ""
txtDataConsegna = ""
lstOrdiniPerCliente.Visible = True

With Me![lstOrdiniPerCliente]
If IsNull(Me!cboOrdiniCliente) Then
       .RowSource = ""
Else
       .RowSource = "SELECT Ordini.IDOrdine, Ordini.DataOrdine, Ordini.DataConsegna " & _
                    "FROM Ordini" & _
                    "WHERE Ordini.IDCliente=" & Me.cboOrdiniCliente.Column(0)
End If
     Call .Requery
End With

End Sub

I tested the query separately and it works as intended: I think I am failing something in the vb syntax that's supposed to pass the value to the SQL. Any thoughts?
 
In your SQL you need a space at the end of each line prior to closing the quote marks and adding & _ other wise everything just runs together into one long string rather than separate statements.
 
thanks to your help I managed.
 

Users who are viewing this thread

Back
Top Bottom