Dear all,
In the code bellow, I am trying to search the value ClientID in the TBRDetail table and load the matching row(s) into ListBox2.
In your opinion, what would be the best option to achieve it?
To be honest, I've managed to load without any problem when there are more than one matching rows, but when only one row matches (only one row needs to be loaded into ListBox2), the values get misaligned as I'm showing you in the image below (they all go into the first column, one below the other).
Thank you so much, your help is much appreciated.
Regards,
<<<<<<<start code>>>>>>>>>>>>>>>>
<<<<<<<finish code>>>>>>>>>>>>>>>>
<<image>>
In the code bellow, I am trying to search the value ClientID in the TBRDetail table and load the matching row(s) into ListBox2.
In your opinion, what would be the best option to achieve it?
To be honest, I've managed to load without any problem when there are more than one matching rows, but when only one row matches (only one row needs to be loaded into ListBox2), the values get misaligned as I'm showing you in the image below (they all go into the first column, one below the other).
Thank you so much, your help is much appreciated.
Regards,
<<<<<<<start code>>>>>>>>>>>>>>>>
>>> You've noted many times <<<
>>> use code - tags <<<
>>> use code - tags <<<
Code:
' Clear ListBox2 before populating it
UserForm1.ListBox2.Clear
' Set up the Command object for the new SQL query
With cmd
.CommandType = adCmdText
.CommandText = "SELECT [Year], [Sales], [KPI], [Sales Quota]" & _
" FROM [TBRDetail] WHERE [Client ID] = '" & ClientID & "'"
End With
' Create a new Recordset object for the SQL query
Set rs = New ADODB.Recordset
' Execute the command and retrieve the results
Set rs = cmd.Execute
If Not rs.EOF Then
End If
<<image>>
Last edited by a moderator: